def __init__(self, logger): Check.__init__(self, logger) self.gauge('system.proc.queue_length') self.gauge('system.proc.count') self.numprocs = WinPDHCounter('System', 'Processes', logger) self.pql = WinPDHCounter('System', 'Processor Queue Length', logger)
def __init__(self, name, init_config, agentConfig, instances=None): AgentCheck.__init__(self, name, init_config, agentConfig, instances) self._countersettypes = {} self._counters = {} self._metrics = {} self._tags = {} try: for instance in instances: key = hash_mutable(instance) counterset = instance.get('countersetname') cfg_tags = instance.get('tags') if cfg_tags is not None: tags = cfg_tags.join(",") self._tags[key] = list(tags) if tags else [] metrics = instance.get('metrics') # list of the metrics. Each entry is itself an entry, # which is the pdh name, datadog metric name, type, and the # pdh counter object self._metrics[key] = [] for inst_name, dd_name, mtype in metrics: m = getattr(self, mtype.lower()) obj = WinPDHCounter(counterset, inst_name, self.log) entry = [inst_name, dd_name, m, obj] self.log.debug("entry: %s" % str(entry)) self._metrics[key].append(entry) except Exception as e: self.log.debug("Exception in PDH init: %s", str(e)) raise
def __init__(self, logger): Check.__init__(self, logger) self.gauge('system.io.wkb_s') self.gauge('system.io.w_s') self.gauge('system.io.rkb_s') self.gauge('system.io.r_s') self.gauge('system.io.avg_q_sz') self.dwbpscounter = WinPDHCounter('LogicalDisk', 'Disk Write Bytes/sec', logger) self.dwpscounter = WinPDHCounter('LogicalDisk', 'Disk Writes/sec', logger) self.drbpscounter = WinPDHCounter('LogicalDisk', 'Disk Read Bytes/sec', logger) self.drpscounter = WinPDHCounter('LogicalDisk', 'Disk Reads/sec', logger) self.qszcounter = WinPDHCounter('LogicalDisk', 'Current Disk Queue Length', logger)
class Processes(Check): def __init__(self, logger): Check.__init__(self, logger) self.gauge('system.proc.queue_length') self.gauge('system.proc.count') self.numprocs = WinPDHCounter('System', 'Processes', logger) self.pql = WinPDHCounter('System', 'Processor Queue Length', logger) def check(self, agentConfig): processor_queue_length = self.pql.get_single_value() processes = self.numprocs.get_single_value() if processor_queue_length is not None: self.save_sample('system.proc.queue_length', processor_queue_length) if processes is not None: self.save_sample('system.proc.count', processes) return self.get_metrics()
def __init__(self, logger): Check.__init__(self, logger) self.gauge('system.mem.free') self.gauge('system.mem.used') self.gauge('system.mem.total') # area of physical memory that stores recently used pages of data # for applications self.gauge('system.mem.cached') # Committed memory is physical memory for which space has been # reserved on the disk paging file in case it must be written # back to disk self.gauge('system.mem.committed') # physical memory used by the operating system, for objects # that can be written to disk when they are not being used self.gauge('system.mem.paged') # physical memory used by the operating system for objects that # cannot be written to disk, but must remain in physical memory # as long as they are allocated. self.gauge('system.mem.nonpaged') # usable = free + cached self.gauge('system.mem.usable') self.gauge('system.mem.pct_usable') # details about the usage of the pagefile. self.gauge('system.mem.pagefile.total') self.gauge('system.mem.pagefile.used') self.gauge('system.mem.pagefile.free') self.gauge('system.mem.pagefile.pct_free') self.cache_bytes_counter = WinPDHCounter('Memory', 'Cache Bytes', logger) self.committed_bytes_counter = WinPDHCounter('Memory', 'Committed Bytes', logger) self.pool_paged_bytes_counter = WinPDHCounter('Memory', 'Pool Paged Bytes', logger) self.pool_non_paged_bytes_counter = WinPDHCounter( 'Memory', 'Pool Nonpaged Bytes', logger)
def __init__(self, name, init_config, agentConfig, instances, counter_list): AgentCheck.__init__(self, name, init_config, agentConfig, instances) self._countersettypes = {} self._counters = {} self._metrics = {} self._tags = {} try: for instance in instances: key = hash_mutable(instance) cfg_tags = instance.get('tags') if cfg_tags is not None: if not isinstance(cfg_tags, list): self.log.error("Tags must be configured as a list") raise ValueError("Tags must be type list, not %s" % str(type(cfg_tags))) self._tags[key] = list(cfg_tags) remote_machine = None host = instance.get('host') self._metrics[key] = [] if host is not None and host != ".": try: remote_machine = host username = instance.get('username') password = instance.get('password') nr = win32wnet.NETRESOURCE() nr.lpRemoteName = r"\\%s\c$" % remote_machine nr.dwType = 0 nr.lpLocalName = None win32wnet.WNetAddConnection2(nr, password, username, 0) except Exception as e: self.log.error("Failed to make remote connection %s" % str(e)) return # list of the metrics. Each entry is itself an entry, # which is the pdh name, datadog metric name, type, and the # pdh counter object for counterset, inst_name, counter_name, dd_name, mtype in counter_list: m = getattr(self, mtype.lower()) obj = WinPDHCounter(counterset, counter_name, self.log, inst_name, machine_name=remote_machine) entry = [inst_name, dd_name, m, obj] self.log.debug("entry: %s" % str(entry)) self._metrics[key].append(entry) # get any additional metrics in the instance addl_metrics = instance.get('additional_metrics') if addl_metrics is not None: for counterset, inst_name, counter_name, dd_name, mtype in addl_metrics: if inst_name.lower() == "none" or len( inst_name ) == 0 or inst_name == "*" or inst_name.lower( ) == "all": inst_name = None m = getattr(self, mtype.lower()) obj = WinPDHCounter(counterset, counter_name, self.log, inst_name, machine_name=remote_machine) entry = [inst_name, dd_name, m, obj] self.log.debug("additional metric entry: %s" % str(entry)) self._metrics[key].append(entry) except Exception as e: self.log.debug("Exception in PDH init: %s", str(e)) raise
class Memory(Check): def __init__(self, logger): Check.__init__(self, logger) self.gauge('system.mem.free') self.gauge('system.mem.used') self.gauge('system.mem.total') # area of physical memory that stores recently used pages of data # for applications self.gauge('system.mem.cached') # Committed memory is physical memory for which space has been # reserved on the disk paging file in case it must be written # back to disk self.gauge('system.mem.committed') # physical memory used by the operating system, for objects # that can be written to disk when they are not being used self.gauge('system.mem.paged') # physical memory used by the operating system for objects that # cannot be written to disk, but must remain in physical memory # as long as they are allocated. self.gauge('system.mem.nonpaged') # usable = free + cached self.gauge('system.mem.usable') self.gauge('system.mem.pct_usable') # details about the usage of the pagefile. self.gauge('system.mem.pagefile.total') self.gauge('system.mem.pagefile.used') self.gauge('system.mem.pagefile.free') self.gauge('system.mem.pagefile.pct_free') self.cache_bytes_counter = WinPDHCounter('Memory', 'Cache Bytes', logger) self.committed_bytes_counter = WinPDHCounter('Memory', 'Committed Bytes', logger) self.pool_paged_bytes_counter = WinPDHCounter('Memory', 'Pool Paged Bytes', logger) self.pool_non_paged_bytes_counter = WinPDHCounter( 'Memory', 'Pool Nonpaged Bytes', logger) def check(self, agentConfig): total = 0 free = 0 cached = 0 mem = psutil.virtual_memory() total_visible_memory_size = mem.total / B2KB free_physical_memory = mem.available / B2KB if total_visible_memory_size is not None and free_physical_memory is not None: total = int(total_visible_memory_size) / KB2MB free = int(free_physical_memory) / KB2MB self.save_sample('system.mem.total', total) self.save_sample('system.mem.free', free) self.save_sample('system.mem.used', total - free) cache_bytes = self.cache_bytes_counter.get_single_value() committed_bytes = self.committed_bytes_counter.get_single_value() pool_paged_bytes = self.pool_paged_bytes_counter.get_single_value() pool_non_paged_bytes = self.pool_non_paged_bytes_counter.get_single_value( ) if cache_bytes is not None: cached = int(cache_bytes) / B2MB self.save_sample('system.mem.cached', cached) if committed_bytes is not None: self.save_sample('system.mem.committed', int(committed_bytes) / B2MB) if pool_paged_bytes is not None: self.save_sample('system.mem.paged', int(pool_paged_bytes) / B2MB) if pool_non_paged_bytes is not None: self.save_sample('system.mem.nonpaged', int(pool_non_paged_bytes) / B2MB) usable = free + cached self.save_sample('system.mem.usable', usable) if total > 0: pct_usable = float(usable) / total self.save_sample('system.mem.pct_usable', pct_usable) # swap_memory pulls from the pagefile data, # rather than from the whole virtual memory data. page = psutil.swap_memory() if page.total is not None: self.save_sample('system.mem.pagefile.total', page.total) self.save_sample('system.mem.pagefile.used', page.used) self.save_sample('system.mem.pagefile.free', page.free) self.save_sample('system.mem.pagefile.pct_free', (100 - page.percent) / 100) return self.get_metrics()
class IO(Check): def __init__(self, logger): Check.__init__(self, logger) self.gauge('system.io.wkb_s') self.gauge('system.io.w_s') self.gauge('system.io.rkb_s') self.gauge('system.io.r_s') self.gauge('system.io.avg_q_sz') self.dwbpscounter = WinPDHCounter('LogicalDisk', 'Disk Write Bytes/sec', logger) self.dwpscounter = WinPDHCounter('LogicalDisk', 'Disk Writes/sec', logger) self.drbpscounter = WinPDHCounter('LogicalDisk', 'Disk Read Bytes/sec', logger) self.drpscounter = WinPDHCounter('LogicalDisk', 'Disk Reads/sec', logger) self.qszcounter = WinPDHCounter('LogicalDisk', 'Current Disk Queue Length', logger) def check(self, agentConfig): dwbps = self.dwbpscounter.get_all_values() dwps = self.dwpscounter.get_all_values() drbps = self.drbpscounter.get_all_values() drps = self.drpscounter.get_all_values() qsz = self.qszcounter.get_all_values() # all of the maps should have the same keys (since there's only one # set of disks blacklist_re = agentConfig.get('device_blacklist_re', None) for device in dwbps: name = self.normalize_device_name(device) if should_ignore_disk(name, blacklist_re): continue disk_write_bytes_per_sec = dwbps[device] disk_writes_per_sec = dwps[device] disk_read_bytes_per_sec = drbps[device] disk_reads_per_sec = drps[device] current_disk_queue_length = qsz[device] if disk_write_bytes_per_sec is not None: self.save_sample('system.io.wkb_s', int(disk_write_bytes_per_sec) / B2KB, device_name=name) if disk_writes_per_sec is not None: self.save_sample('system.io.w_s', int(disk_writes_per_sec), device_name=name) if disk_read_bytes_per_sec is not None: self.save_sample('system.io.rkb_s', int(disk_read_bytes_per_sec) / B2KB, device_name=name) if disk_reads_per_sec is not None: self.save_sample('system.io.r_s', int(disk_reads_per_sec), device_name=name) if current_disk_queue_length is not None: self.save_sample('system.io.avg_q_sz', current_disk_queue_length, device_name=name) return self.get_metrics()
def __init__(self, name, init_config, agentConfig, instances, counter_list): AgentCheck.__init__(self, name, init_config, agentConfig, instances) self._countersettypes = {} self._counters = {} self._metrics = {} self._tags = {} try: for instance in instances: key = hash_mutable(instance) cfg_tags = instance.get('tags') if cfg_tags is not None: if not isinstance(cfg_tags, list): self.log.error("Tags must be configured as a list") raise ValueError("Tags must be type list, not %s" % str(type(cfg_tags))) self._tags[key] = list(cfg_tags) remote_machine = None host = instance.get('host') self._metrics[key] = [] if host is not None and host != ".": try: remote_machine = host username = instance.get('username') password = instance.get('password') nr = win32wnet.NETRESOURCE() nr.lpRemoteName = r"\\%s\c$" % remote_machine nr.dwType = 0 nr.lpLocalName = None win32wnet.WNetAddConnection2(nr, password, username, 0) except Exception as e: self.log.error("Failed to make remote connection %s" % str(e)) return ## counter_data_types allows the precision with which counters are queried ## to be configured on a per-metric basis. In the metric instance, precision ## should be specified as ## counter_data_types: ## - iis.httpd_request_method.get,int ## - iis.net.bytes_rcvd,float ## ## the above would query the counter associated with iis.httpd_request_method.get ## as an integer (LONG) and iis.net.bytes_rcvd as a double datatypes = {} precisions = instance.get('counter_data_types') if precisions is not None: if not isinstance(precisions, list): self.log.warning( "incorrect type for counter_data_type %s" % str(precisions)) else: for p in precisions: k, v = p.split(",") v = v.lower().strip() if v in int_types: self.log.info( "Setting datatype for %s to integer" % k) datatypes[k] = DATA_TYPE_INT elif v in double_types: self.log.info( "Setting datatype for %s to double" % k) datatypes[k] = DATA_TYPE_DOUBLE else: self.log.warning("Unknown data type %s" % str(v)) # list of the metrics. Each entry is itself an entry, # which is the pdh name, datadog metric name, type, and the # pdh counter object for counterset, inst_name, counter_name, dd_name, mtype in counter_list: m = getattr(self, mtype.lower()) precision = datatypes.get(dd_name) obj = WinPDHCounter(counterset, counter_name, self.log, inst_name, machine_name=remote_machine, precision=precision) entry = [inst_name, dd_name, m, obj] self.log.debug("entry: %s" % str(entry)) self._metrics[key].append(entry) # get any additional metrics in the instance addl_metrics = instance.get('additional_metrics') if addl_metrics is not None: for counterset, inst_name, counter_name, dd_name, mtype in addl_metrics: if inst_name.lower() == "none" or len( inst_name ) == 0 or inst_name == "*" or inst_name.lower( ) == "all": inst_name = None m = getattr(self, mtype.lower()) precision = datatypes.get(dd_name) obj = WinPDHCounter(counterset, counter_name, self.log, inst_name, machine_name=remote_machine, precision=precision) entry = [inst_name, dd_name, m, obj] self.log.debug("additional metric entry: %s" % str(entry)) self._metrics[key].append(entry) except Exception as e: self.log.debug("Exception in PDH init: %s", str(e)) raise