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()
class Cpu(Check): def __init__(self, logger): Check.__init__(self, logger) self.counter('system.cpu.user') self.counter('system.cpu.idle') self.counter('system.cpu.system') self.counter('system.cpu.interrupt') self.cpu_interrupt_counter = WinPDHCounter('Processor', '% Interrupt Time', logger, instance_name="_Total") def check(self, agentConfig): cpu_percent = psutil.cpu_times() self.save_sample('system.cpu.user', 100 * cpu_percent.user / psutil.cpu_count()) self.save_sample('system.cpu.idle', 100 * cpu_percent.idle / psutil.cpu_count()) self.save_sample('system.cpu.system', 100 * cpu_percent.system / psutil.cpu_count()) interrupt = self.cpu_interrupt_counter.get_single_value() self.save_sample('system.cpu.interrupt', 100 * interrupt) return self.get_metrics()
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()