mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
Merge pull request #1115 from zivillian/kvm_mem
* remove empty line from config (causing an error message) * switch to python3
This commit is contained in:
commit
6906c857cd
1 changed files with 12 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vim: set fileencoding=utf-8
|
# vim: set fileencoding=utf-8
|
||||||
#
|
#
|
||||||
|
@ -25,18 +25,13 @@ def config(vm_names):
|
||||||
graph_vlabel Bytes
|
graph_vlabel Bytes
|
||||||
graph_category virtualization
|
graph_category virtualization
|
||||||
graph_info This graph shows the current amount of memory used by virtual machines
|
graph_info This graph shows the current amount of memory used by virtual machines
|
||||||
graph_args --base 1024
|
graph_args --base 1024 -l 0"""
|
||||||
"""
|
print(base_config)
|
||||||
print base_config
|
|
||||||
draw = "AREA"
|
|
||||||
for vm in vm_names:
|
for vm in vm_names:
|
||||||
print "%s_mem.label %s" % (vm, vm)
|
print("%s_mem.label %s" % (vm, vm))
|
||||||
print "%s_mem.type GAUGE" % vm
|
print("%s_mem.type GAUGE" % vm)
|
||||||
if draw == 'AREA':
|
print("%s_mem.draw %s" % (vm, "AREASTACK"))
|
||||||
print "%s_mem.min 0" % vm
|
print("%s_mem.info memory used by virtual machine %s" % (vm, vm))
|
||||||
print "%s_mem.draw %s" % (vm, draw)
|
|
||||||
print "%s_mem.info memory used by virtual machine %s" % (vm, vm)
|
|
||||||
draw = "STACK"
|
|
||||||
|
|
||||||
|
|
||||||
def clean_vm_name(vm_name):
|
def clean_vm_name(vm_name):
|
||||||
|
@ -69,12 +64,12 @@ def fetch(vms):
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||||
amount = re.sub(r"^.*-m\x00(.*)\x00-smp.*$",r"\1", cmdline.readline())
|
amount = re.sub(r"^.*-m\x00(.*)\x00-smp.*$",r"\1", cmdline.readline())
|
||||||
amount = int(amount) * 1024 * 1024
|
amount = int(amount) * 1024 * 1024
|
||||||
print "%s_mem.value %s" % (vms[pid], amount)
|
print("%s_mem.value %s" % (vms[pid], amount))
|
||||||
except:
|
except:
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||||
amount = re.sub(r"^.*-m\x00(\d+).*$",r"\1", cmdline.readline())
|
amount = re.sub(r"^.*-m\x00(\d+).*$",r"\1", cmdline.readline())
|
||||||
amount = int(amount) * 1024 * 1024
|
amount = int(amount) * 1024 * 1024
|
||||||
print "%s_mem.value %s" % (vms[pid], amount)
|
print("%s_mem.value %s" % (vms[pid], amount))
|
||||||
|
|
||||||
def detect_kvm():
|
def detect_kvm():
|
||||||
''' Check if kvm is installed
|
''' Check if kvm is installed
|
||||||
|
@ -97,16 +92,16 @@ def list_pids():
|
||||||
''' Find the pid of kvm processes
|
''' Find the pid of kvm processes
|
||||||
@return a list of pids from running kvm
|
@return a list of pids from running kvm
|
||||||
'''
|
'''
|
||||||
pid = Popen("pidof qemu-kvm qemu-system-x86_64 kvm", shell=True, stdout=PIPE)
|
pid = Popen("pidof qemu-kvm qemu-system-x86_64 kvm", shell=True, stdout=PIPE, text=True)
|
||||||
return pid.communicate()[0].split()
|
return pid.communicate()[0].split()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
if sys.argv[1] in ['autoconf', 'detect']:
|
if sys.argv[1] in ['autoconf', 'detect']:
|
||||||
if detect_kvm():
|
if detect_kvm():
|
||||||
print "yes"
|
print("yes")
|
||||||
else:
|
else:
|
||||||
print "no"
|
print("no")
|
||||||
elif sys.argv[1] == "config":
|
elif sys.argv[1] == "config":
|
||||||
config(find_vm_names(list_pids()).values())
|
config(find_vm_names(list_pids()).values())
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue