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:
parent
7f98e21f2b
commit
f6080f5f8e
1 changed files with 10 additions and 6 deletions
|
@ -18,6 +18,7 @@
|
||||||
import re, os, sys
|
import re, os, sys
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
|
|
||||||
def config(vm_names):
|
def config(vm_names):
|
||||||
""" Print the plugin's config
|
""" Print the plugin's config
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ graph_args --base 1024
|
||||||
print "%s_out.min 0" % vm
|
print "%s_out.min 0" % vm
|
||||||
print "%s_out.draw LINE2" % vm
|
print "%s_out.draw LINE2" % vm
|
||||||
|
|
||||||
|
|
||||||
def clean_vm_name(vm_name):
|
def clean_vm_name(vm_name):
|
||||||
""" Replace all special chars
|
""" Replace all special chars
|
||||||
|
|
||||||
|
@ -51,9 +53,9 @@ def clean_vm_name(vm_name):
|
||||||
suffix = os.getenv("vmsuffix")
|
suffix = os.getenv("vmsuffix")
|
||||||
if suffix:
|
if suffix:
|
||||||
vm_name = re.sub(suffix, "", vm_name)
|
vm_name = re.sub(suffix, "", vm_name)
|
||||||
|
|
||||||
return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name)
|
return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name)
|
||||||
|
|
||||||
|
|
||||||
def fetch(vms):
|
def fetch(vms):
|
||||||
""" Fetch values for a list of pids
|
""" Fetch values for a list of pids
|
||||||
|
|
||||||
|
@ -73,12 +75,14 @@ def fetch(vms):
|
||||||
print inst
|
print inst
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
def detect_kvm():
|
def detect_kvm():
|
||||||
""" Check if kvm is installed """
|
""" Check if kvm is installed """
|
||||||
kvm = Popen("which kvm", shell=True, stdout=PIPE)
|
kvm = Popen("which kvm", shell=True, stdout=PIPE)
|
||||||
kvm.communicate()
|
kvm.communicate()
|
||||||
return not bool(kvm.returncode)
|
return not bool(kvm.returncode)
|
||||||
|
|
||||||
|
|
||||||
def find_vm_names(pids):
|
def find_vm_names(pids):
|
||||||
"""Find and clean vm names from pids
|
"""Find and clean vm names from pids
|
||||||
|
|
||||||
|
@ -87,9 +91,10 @@ def find_vm_names(pids):
|
||||||
result = {}
|
result = {}
|
||||||
for pid in pids:
|
for pid in pids:
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||||
result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline()))
|
result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline()))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_vm_mac(pid):
|
def get_vm_mac(pid):
|
||||||
"""Find and clean vm names from pids
|
"""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)
|
mac = re.sub(r"^.*ifname=(tap[^,]+),.*$",r"\1", line)
|
||||||
return mac
|
return mac
|
||||||
|
|
||||||
|
|
||||||
def list_pids():
|
def list_pids():
|
||||||
""" Find the pid of kvm processes
|
""" Find the pid of kvm processes
|
||||||
|
|
||||||
|
@ -122,5 +128,3 @@ if __name__ == "__main__":
|
||||||
fetch(find_vm_names(list_pids()))
|
fetch(find_vm_names(list_pids()))
|
||||||
else:
|
else:
|
||||||
fetch(find_vm_names(list_pids()))
|
fetch(find_vm_names(list_pids()))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue