1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

kvm_net: unify whitespace

This commit is contained in:
Lars Kruse 2018-06-10 17:35:31 +02:00
parent 7f98e21f2b
commit f6080f5f8e

View file

@ -18,6 +18,7 @@
import re, os, sys
from subprocess import Popen, PIPE
def config(vm_names):
""" Print the plugin's config
@ -41,6 +42,7 @@ graph_args --base 1024
print "%s_out.min 0" % vm
print "%s_out.draw LINE2" % vm
def clean_vm_name(vm_name):
""" Replace all special chars
@ -51,9 +53,9 @@ def clean_vm_name(vm_name):
suffix = os.getenv("vmsuffix")
if suffix:
vm_name = re.sub(suffix, "", vm_name)
return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name)
def fetch(vms):
""" Fetch values for a list of pids
@ -73,12 +75,14 @@ def fetch(vms):
print inst
continue
def detect_kvm():
""" Check if kvm is installed """
kvm = Popen("which kvm", shell=True, stdout=PIPE)
kvm.communicate()
return not bool(kvm.returncode)
def find_vm_names(pids):
"""Find and clean vm names from pids
@ -90,6 +94,7 @@ def find_vm_names(pids):
result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline()))
return result
def get_vm_mac(pid):
"""Find and clean vm names from pids
@ -100,6 +105,7 @@ def get_vm_mac(pid):
mac = re.sub(r"^.*ifname=(tap[^,]+),.*$",r"\1", line)
return mac
def list_pids():
""" Find the pid of kvm processes
@ -122,5 +128,3 @@ if __name__ == "__main__":
fetch(find_vm_names(list_pids()))
else:
fetch(find_vm_names(list_pids()))