mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
use /proc/pid/stat
This commit is contained in:
parent
e1816224a9
commit
e78a159051
@ -21,18 +21,21 @@ def config(vm_names):
|
||||
''' Print the plugin's config
|
||||
@param vm_names : a list of "cleaned" vms' name
|
||||
'''
|
||||
percent = len(filter(lambda x: x[0:3] == 'cpu' and x[3] != ' ', open('/proc/stat', 'r').readlines())) * 100
|
||||
|
||||
base_config = """graph_title KVM Virtual Machine CPU usage
|
||||
graph_vlabel %
|
||||
graph_vlabel %%
|
||||
graph_category KVM
|
||||
graph_scale no
|
||||
graph_period second
|
||||
graph_info This graph shows the current CPU used by virtual machines
|
||||
graph_args --base 1000
|
||||
"""
|
||||
graph_args --base 1000 -r --lower-limit 0 --upper-limit %d""" % percent
|
||||
print base_config
|
||||
draw = "AREA"
|
||||
for vm in vm_names:
|
||||
print "%s_cpu.label %s" % (vm, vm)
|
||||
print "%s_cpu.type GAUGE" % vm
|
||||
print "%s_cpu.min 0" % vm
|
||||
print "%s_cpu.type DERIVE" % vm
|
||||
print "%s_cpu.draw %s" % (vm, draw)
|
||||
print "%s_cpu.info percent of cpu time used by virtual machine" % vm
|
||||
draw = "STACK"
|
||||
@ -79,17 +82,9 @@ def fetch(vms):
|
||||
''' Fetch values for a list of pids
|
||||
@param dictionnary {kvm_pid: cleaned vm name}
|
||||
'''
|
||||
pidx = Popen("top -b -n 1 ", shell=True, stdout=PIPE)
|
||||
res = pidx.communicate()[0].split('\n')
|
||||
for line in res:
|
||||
try:
|
||||
tap = line.split()[0]
|
||||
cpu = line.split()[8]
|
||||
for pid in vms:
|
||||
if tap == pid:
|
||||
print '%s_cpu.value %s' % (vms[pid], cpu)
|
||||
except:
|
||||
continue
|
||||
for ( pid, name ) in vms.iteritems():
|
||||
( user, system ) = open("/proc/%s/stat" % pid, 'r').readline().split(' ')[13:15]
|
||||
print '%s_cpu.value %d' % ( name, int(user) + int(system) )
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
|
Loading…
Reference in New Issue
Block a user