def __init__(self, argv=(), env=None, debug=False): """Populate Munin Plugin with MuninGraph instances. @param argv: List of command line arguments. @param env: Dictionary of environment variables. @param debug: Print debugging messages if True. (Default: False) """ MuninPlugin.__init__(self, argv, env, debug) self._category = 'System' self._sysinfo = SystemInfo() self._loadstats = None self._cpustats = None self._memstats = None self._procstats = None self._vmstats = None if self.graphEnabled('sys_loadavg'): graph = MuninGraph('Load Average', self._category, info='Load Average (15 min, 5 min, 1 min).', args='--base 1000 --lower-limit 0') graph.addField('load15min', '15 min', type='GAUGE', draw='AREA') graph.addField('load5min', '5 min', type='GAUGE', draw='LINE1') graph.addField('load1min', '1 min', type='GAUGE', draw='LINE1') self.appendGraph('sys_loadavg', graph) if self.graphEnabled('sys_cpu_util'): self._cpustats = self._sysinfo.getCPUuse() graph = MuninGraph('CPU Utilization (%)', self._category, info='System CPU Utilization.', args='--base 1000 --lower-limit 0') for field in [ 'system', 'user', 'nice', 'idle', 'iowait', 'irq', 'softirq', 'steal', 'guest' ]: if self._cpustats.has_key(field): graph.addField(field, field, type='DERIVE', min=0, cdef='%s,10,/' % field, draw='AREASTACK') self.appendGraph('sys_cpu_util', graph) if self.graphEnabled('sys_mem_util'): if self._memstats is None: self._memstats = self._sysinfo.getMemoryUse() self._memstats['MemUsed'] = self._memstats['MemTotal'] for field in ['MemFree', 'SwapCached', 'Buffers', 'Cached']: if self._memstats.has_key(field): self._memstats['MemUsed'] -= self._memstats[field] self._memstats['SwapUsed'] = (self._memstats['SwapTotal'] - self._memstats['SwapFree']) graph = MuninGraph('Memory Utilization (bytes)', self._category, info='System Memory Utilization in bytes.', args='--base 1024 --lower-limit 0') for field in [ 'MemUsed', 'SwapCached', 'Buffers', 'Cached', 'MemFree', 'SwapUsed' ]: if self._memstats.has_key(field): graph.addField(field, field, type='GAUGE', draw='AREASTACK') self.appendGraph('sys_mem_util', graph) if self.graphEnabled('sys_mem_avail'): if self._memstats is None: self._memstats = self._sysinfo.getMemoryUse() if self._memstats.has_key('Hugepagesize'): self._memstats['MemHugePages'] = ( self._memstats['HugePages_Total'] * self._memstats['Hugepagesize']) self._memstats['MemKernel'] = self._memstats['MemTotal'] for field in ['MemHugePages', 'Active', 'Inactive', 'MemFree']: if self._memstats.has_key(field): self._memstats['MemKernel'] -= self._memstats[field] graph = MuninGraph( 'Memory Utilization - Active/Inactive (bytes)', self._category, info='System Memory Utilization (Active/Inactive) in bytes.', args='--base 1024 --lower-limit 0') for field in [ 'MemKernel', 'MemHugePages', 'Active', 'Inactive', 'MemFree' ]: if self._memstats.has_key(field): graph.addField(field, field, type='GAUGE', draw='AREASTACK') self.appendGraph('sys_mem_avail', graph) if self.graphEnabled('sys_mem_huge'): if self._memstats is None: self._memstats = self._sysinfo.getMemoryUse() if (self._memstats.has_key('Hugepagesize') and self._memstats['HugePages_Total'] > 0): graph = MuninGraph( 'Memory Utilization - Huge Pages (bytes)', self._category, info='System Memory Huge Pages Utilization in bytes.', args='--base 1024 --lower-limit 0') for field in ['Rsvd', 'Surp', 'Free']: fkey = 'HugePages_' + field if self._memstats.has_key(fkey): graph.addField(field, field, type='GAUGE', draw='AREASTACK') self.appendGraph('sys_mem_huge', graph) if self.graphEnabled('sys_processes'): graph = MuninGraph( 'Processes', self._category, info='Number of processes in running and blocked state.', args='--base 1000 --lower-limit 0') graph.addField('running', 'running', type='GAUGE', draw='AREASTACK') graph.addField('blocked', 'blocked', type='GAUGE', draw='AREASTACK') self.appendGraph('sys_processes', graph) if self.graphEnabled('sys_forks'): graph = MuninGraph('Process Forks per Second', self._category, info='Process Forks per Second.', args='--base 1000 --lower-limit 0') graph.addField('forks', 'forks', type='DERIVE', min=0, draw='LINE2') self.appendGraph('sys_forks', graph) if self.graphEnabled('sys_intr_ctxt'): if self._procstats is None: self._procstats = self._sysinfo.getProcessStats() graph = MuninGraph( 'Interrupts and Context Switches per Second', self._category, info='Interrupts and Context Switches per Second', args='--base 1000 --lower-limit 0') labels = ['irq', 'softirq', 'ctxt'] infos = [ 'Hardware Interrupts per second', 'Software Interrupts per second.', 'Context Switches per second.' ] idx = 0 for field in ['intr', 'softirq', 'ctxt']: if self._procstats.has_key(field): graph.addField(field, labels[idx], type='DERIVE', min=0, draw='LINE2', info=infos[idx]) idx += 1 self.appendGraph('sys_intr_ctxt', graph) if self.graphEnabled('sys_vm_paging'): graph = MuninGraph( 'VM - Paging', self._category, info= 'Virtual Memory Paging: Pages In (-) / Out (+) per Second.', args='--base 1000 --lower-limit 0', vlabel='pages in (-) / out (+) per second') graph.addField('in', 'pages', type='DERIVE', min=0, draw='LINE2', graph=False) graph.addField('out', 'pages', type='DERIVE', min=0, draw='LINE2', negative='in') self.appendGraph('sys_vm_paging', graph) if self.graphEnabled('sys_vm_swapping'): graph = MuninGraph( 'VM - Swapping', self._category, info= 'Virtual Memory Swapping: Pages In (-) / Out (+) per Second.', args='--base 1000 --lower-limit 0', vlabel='pages in (-) / out (+) per second') graph.addField('in', 'pages', type='DERIVE', min=0, draw='LINE2', graph=False) graph.addField('out', 'pages', type='DERIVE', min=0, draw='LINE2', negative='in') self.appendGraph('sys_vm_swapping', graph)