mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Plugin-Gallery: get better 2nd level headings
This commit is contained in:
parent
8481ea1566
commit
f5b816df9e
25 changed files with 11 additions and 7 deletions
102
plugins/libvirt/kvm_cpu
Executable file
102
plugins/libvirt/kvm_cpu
Executable file
|
@ -0,0 +1,102 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: set fileencoding=utf-8
|
||||
#
|
||||
# Munin plugin to show CPU used by vm
|
||||
#
|
||||
# Copyright Maxence Dunnewind, Rodolphe Quiédeville
|
||||
#
|
||||
# License : GPLv3
|
||||
#
|
||||
# parsed environment variables:
|
||||
# vmsuffix: part of vm name to be removed
|
||||
#
|
||||
#%# capabilities=autoconf
|
||||
#%# family=contrib
|
||||
|
||||
import re, os, sys
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
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_category Virtualization
|
||||
graph_scale no
|
||||
graph_period second
|
||||
graph_info This graph shows the current CPU used by virtual machines
|
||||
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.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"
|
||||
|
||||
|
||||
def clean_vm_name(vm_name):
|
||||
''' Replace all special chars
|
||||
@param vm_name : a vm's name
|
||||
@return cleaned vm's name
|
||||
'''
|
||||
|
||||
# suffix part defined in conf
|
||||
suffix = os.getenv('vmsuffix')
|
||||
if suffix:
|
||||
vm_name = re.sub(suffix,'',vm_name)
|
||||
|
||||
return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name)
|
||||
|
||||
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
|
||||
@return a dictionnary of {pids : cleaned vm name}
|
||||
'''
|
||||
result = {}
|
||||
for pid in pids:
|
||||
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()))
|
||||
return result
|
||||
|
||||
def list_pids():
|
||||
''' Find the pid of kvm processes
|
||||
@return a list of pids from running kvm
|
||||
'''
|
||||
pid = Popen("pidof qemu-system-x86_64", shell=True, stdout=PIPE)
|
||||
return pid.communicate()[0].split()
|
||||
|
||||
def fetch(vms):
|
||||
''' Fetch values for a list of pids
|
||||
@param dictionnary {kvm_pid: cleaned vm name}
|
||||
'''
|
||||
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:
|
||||
if sys.argv[1] in ['autoconf', 'detect']:
|
||||
if detect_kvm():
|
||||
print "yes"
|
||||
else:
|
||||
print "no"
|
||||
elif sys.argv[1] == "config":
|
||||
config(find_vm_names(list_pids()).values())
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
||||
|
110
plugins/libvirt/kvm_io
Executable file
110
plugins/libvirt/kvm_io
Executable file
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: set fileencoding=utf-8
|
||||
#
|
||||
# Munin plugin to show io by vm
|
||||
#
|
||||
# Copyright Maxence Dunnewind, Rodolphe Quiédeville
|
||||
#
|
||||
# License : GPLv3
|
||||
#
|
||||
# parsed environment variables:
|
||||
# vmsuffix: part of vm name to be removed
|
||||
#
|
||||
#%# capabilities=autoconf
|
||||
#%# family=contrib
|
||||
|
||||
import re, os, sys
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
def config(vm_names):
|
||||
''' Print the plugin's config
|
||||
@param vm_names : a list of "cleaned" vms' name
|
||||
'''
|
||||
base_config = """graph_title KVM Virtual Machine IO usage
|
||||
graph_vlabel Bytes read(-)/written(+) per second
|
||||
graph_category Virtualization
|
||||
graph_info This graph shows the block device I/O used of virtual machines
|
||||
graph_args --base 1024
|
||||
"""
|
||||
print base_config
|
||||
|
||||
for vm in vm_names:
|
||||
print "%s_read.label %s" % (vm, vm)
|
||||
print "%s_read.type COUNTER" % vm
|
||||
print "%s_read.min 0" % vm
|
||||
print "%s_read.draw LINE1" % vm
|
||||
print "%s_read.info I/O used by virtual machine %s" % (vm, vm)
|
||||
print "%s_write.label %s" % (vm, vm)
|
||||
print "%s_write.type COUNTER" % vm
|
||||
print "%s_write.min 0" % vm
|
||||
print "%s_write.draw LINE1" % vm
|
||||
print "%s_write.negative %s_read" % (vm, vm)
|
||||
print "%s_write.info I/O used by virtual machine %s" % (vm, vm)
|
||||
|
||||
def clean_vm_name(vm_name):
|
||||
''' Replace all special chars
|
||||
@param vm_name : a vm's name
|
||||
@return cleaned vm's name
|
||||
'''
|
||||
# suffix part defined in conf
|
||||
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
|
||||
@param dictionnary {kvm_pid: cleaned vm name}
|
||||
'''
|
||||
res = {}
|
||||
for pid in vms:
|
||||
f = open("/proc/%s/io" % pid, "r")
|
||||
for line in f.readlines():
|
||||
if "read_bytes" in line:
|
||||
read = line.split()[1]
|
||||
print "%s_read.value %s" % (vms[pid], read)
|
||||
if "write_bytes" in line:
|
||||
write = line.split()[1]
|
||||
print "%s_write.value %s" % (vms[pid], write)
|
||||
break
|
||||
f.close()
|
||||
|
||||
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
|
||||
@return a dictionnary of {pids : cleaned vm name}
|
||||
'''
|
||||
result = {}
|
||||
for pid in pids:
|
||||
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()))
|
||||
return result
|
||||
|
||||
def list_pids():
|
||||
''' Find the pid of kvm processes
|
||||
@return a list of pids from running kvm
|
||||
'''
|
||||
pid = Popen("pidof qemu-system-x86_64", shell=True, stdout=PIPE)
|
||||
return pid.communicate()[0].split()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] in ['autoconf', 'detect']:
|
||||
if detect_kvm():
|
||||
print "yes"
|
||||
else:
|
||||
print "no"
|
||||
elif sys.argv[1] == "config":
|
||||
config(find_vm_names(list_pids()).values())
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
107
plugins/libvirt/kvm_mem
Executable file
107
plugins/libvirt/kvm_mem
Executable file
|
@ -0,0 +1,107 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: set fileencoding=utf-8
|
||||
#
|
||||
# Munin plugin to show amount of memory used by vm
|
||||
#
|
||||
# Copyright Maxence Dunnewind, Rodolphe Quiédeville, Adrien Pujol
|
||||
#
|
||||
# License : GPLv3
|
||||
#
|
||||
# parsed environment variables:
|
||||
# vmsuffix: part of vm name to be removed
|
||||
#
|
||||
#%# capabilities=autoconf
|
||||
#%# family=contrib
|
||||
|
||||
import re, os, sys
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
def config(vm_names):
|
||||
''' Print the plugin's config
|
||||
@param vm_names : a list of "cleaned" vms' name
|
||||
'''
|
||||
base_config = """graph_title KVM Virtual Machine Memory usage
|
||||
graph_vlabel Bytes
|
||||
graph_category Virtualization
|
||||
graph_info This graph shows the current amount of memory used by virtual machines
|
||||
graph_args --base 1024
|
||||
"""
|
||||
print base_config
|
||||
draw = "AREA"
|
||||
for vm in vm_names:
|
||||
print "%s_mem.label %s" % (vm, vm)
|
||||
print "%s_mem.type GAUGE" % vm
|
||||
if draw == 'AREA':
|
||||
print "%s_mem.min 0" % 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):
|
||||
''' Replace all special chars
|
||||
@param vm_name : a vm's name
|
||||
@return cleaned vm's name
|
||||
'''
|
||||
# suffix part defined in conf
|
||||
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
|
||||
@param dictionnary {kvm_pid: cleaned vm name}
|
||||
'''
|
||||
res = {}
|
||||
for pid in vms:
|
||||
try:
|
||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||
amount = re.sub(r"^.*-m\x00(.*)\x00-smp.*$",r"\1", cmdline.readline())
|
||||
amount = int(amount) * 1024 * 1024
|
||||
print "%s_mem.value %s" % (vms[pid], amount)
|
||||
except:
|
||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||
amount = re.sub(r"^.*-m\x00(\d+).*$",r"\1", cmdline.readline())
|
||||
amount = int(amount) * 1024 * 1024
|
||||
print "%s_mem.value %s" % (vms[pid], amount)
|
||||
|
||||
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
|
||||
@return a dictionnary of {pids : cleaned vm name}
|
||||
'''
|
||||
result = {}
|
||||
for pid in pids:
|
||||
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()))
|
||||
return result
|
||||
|
||||
def list_pids():
|
||||
''' Find the pid of kvm processes
|
||||
@return a list of pids from running kvm
|
||||
'''
|
||||
pid = Popen("pidof qemu-system-x86_64", shell=True, stdout=PIPE)
|
||||
return pid.communicate()[0].split()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] in ['autoconf', 'detect']:
|
||||
if detect_kvm():
|
||||
print "yes"
|
||||
else:
|
||||
print "no"
|
||||
elif sys.argv[1] == "config":
|
||||
config(find_vm_names(list_pids()).values())
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
141
plugins/libvirt/kvm_net
Executable file
141
plugins/libvirt/kvm_net
Executable file
|
@ -0,0 +1,141 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: set fileencoding=utf-8
|
||||
#
|
||||
# Munin plugin to show the network I/O per vm
|
||||
#
|
||||
# Copyright Igor Borodikhin
|
||||
#
|
||||
# License : GPLv3
|
||||
#
|
||||
#
|
||||
# parsed environment variables:
|
||||
# vmsuffix: part of vm name to be removed
|
||||
#
|
||||
#%# capabilities=autoconf
|
||||
#%# family=contrib
|
||||
|
||||
import re, os, sys
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
def config(vm_names):
|
||||
''' Print the plugin's config
|
||||
@param vm_names : a list of "cleaned" vms' name
|
||||
'''
|
||||
base_config = """graph_title KVM Network I/O
|
||||
graph_vlabel Bytes rx(-)/tx(+) per second
|
||||
graph_category Virtualization
|
||||
graph_info This graph shows the network I/O of the virtual machines
|
||||
graph_args --base 1024
|
||||
"""
|
||||
print base_config
|
||||
for vm in vm_names:
|
||||
print "%s_in.label %s" % (vm, vm)
|
||||
print "%s_in.type COUNTER" % vm
|
||||
print "%s_in.min 0" % vm
|
||||
print "%s_in.draw LINE2" % vm
|
||||
print "%s_out.negative %s_in" % (vm, vm)
|
||||
print "%s_out.label %s" % (vm, vm)
|
||||
print "%s_out.type COUNTER" % vm
|
||||
print "%s_out.min 0" % vm
|
||||
print "%s_out.draw LINE2" % vm
|
||||
|
||||
def clean_vm_name(vm_name):
|
||||
''' Replace all special chars
|
||||
@param vm_name : a vm's name
|
||||
@return cleaned vm's name
|
||||
'''
|
||||
# suffix part defined in conf
|
||||
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
|
||||
@param dictionnary {kvm_pid: cleaned vm name}
|
||||
'''
|
||||
res = {}
|
||||
for pid in vms:
|
||||
tap = get_vm_mac(pid)
|
||||
try:
|
||||
f = open("/proc/net/dev", "r")
|
||||
for line in f.readlines():
|
||||
if tap in line:
|
||||
print "%s_in.value %s" % (vms[pid], re.sub(r"%s:"%tap, "", line.split()[0]))
|
||||
print "%s_out.value %s" % (vms[pid], line.split()[8])
|
||||
break
|
||||
except Exception as inst:
|
||||
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
|
||||
@return a dictionnary of {pids : cleaned vm name}
|
||||
'''
|
||||
result = {}
|
||||
for pid in pids:
|
||||
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()))
|
||||
return result
|
||||
|
||||
def get_vm_mac(pid):
|
||||
'''Find and clean vm names from pids
|
||||
@return the mac address for a specified pid
|
||||
'''
|
||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||
line = cmdline.readline()
|
||||
mac = re.sub(r"^.*ifname=(tap[^,]+),.*$",r"\1", line)
|
||||
return mac
|
||||
|
||||
def list_pids():
|
||||
''' Find the pid of kvm processes
|
||||
@return a list of pids from running kvm
|
||||
'''
|
||||
pid = Popen("pidof qemu-system-x86_64", shell=True, stdout=PIPE)
|
||||
return pid.communicate()[0].split()
|
||||
|
||||
def find_vms_tap():
|
||||
''' Check if kvm is installed
|
||||
@return a list of pids from running kvm
|
||||
'''
|
||||
result = []
|
||||
tap = ""
|
||||
mac = ""
|
||||
kvm = Popen("ip a | grep -A 1 tap | awk '{print $2}' | grep -v '^$'", shell=True, stdout=PIPE)
|
||||
res = kvm.communicate()[0].split('\n')
|
||||
for line in res:
|
||||
try:
|
||||
if len(line) > 0:
|
||||
if re.match(r"^tap.*", line):
|
||||
tap = re.sub(r"(tap[^:]+):", r"\1", line)
|
||||
else:
|
||||
result.append(tap)
|
||||
except Exception as inst:
|
||||
continue
|
||||
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] in ['autoconf', 'detect']:
|
||||
if detect_kvm():
|
||||
print "yes"
|
||||
else:
|
||||
print "no"
|
||||
elif sys.argv[1] == "config":
|
||||
config(find_vm_names(list_pids()).values())
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
||||
else:
|
||||
fetch(find_vm_names(list_pids()))
|
||||
|
||||
|
1300
plugins/libvirt/libvirt
Executable file
1300
plugins/libvirt/libvirt
Executable file
File diff suppressed because it is too large
Load diff
59
plugins/libvirt/munin-libvirtpy
Executable file
59
plugins/libvirt/munin-libvirtpy
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Revision 1.0 2008/05/16 - Steven Wagner
|
||||
# First functional release. Works for me.
|
||||
#
|
||||
# Revision 0.5 2008/05/01 - Julien Rottenberg
|
||||
# initial display of variables from libvirt
|
||||
|
||||
#python-libvirt is required
|
||||
|
||||
import libvirt
|
||||
import sys
|
||||
|
||||
conn = libvirt.openReadOnly("qemu:///system")
|
||||
if conn == None:
|
||||
print 'Failed to open connection to the hypervisor'
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
(model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo()
|
||||
except:
|
||||
print 'getInfo failed'
|
||||
sys.exit(1)
|
||||
|
||||
#print
|
||||
#print "KVM running on %d %s %d mhz CPUs w/ %d MB RAM." % (cpus, model, mhz, memory)
|
||||
#print
|
||||
|
||||
ids = conn.listDomainsID()
|
||||
if ids == None or len(ids) == 0:
|
||||
print 'No running domains found.'
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
if sys.argv[1] == "config":
|
||||
print "graph_title KVM Domain CPU Utilization"
|
||||
print "graph_vlabel CPU use in seconds"
|
||||
print "graph_args --base 1000"
|
||||
print "graph_category Virtualization"
|
||||
|
||||
for id in ids:
|
||||
dom = conn.lookupByID(id)
|
||||
nodeName = dom.name()
|
||||
print "%s.type COUNTER" %(nodeName)
|
||||
print "%s.label %s" %(nodeName, nodeName)
|
||||
sys.exit(1)
|
||||
|
||||
for id in ids:
|
||||
dom = conn.lookupByID(id)
|
||||
state, maxMem, memory, numVirtCpu, cpuTime = dom.info()
|
||||
nodeName = dom.name()
|
||||
# uuid = dom.UUID()
|
||||
# ostype = dom.OSType()
|
||||
# print """Domain: %s, %s state (%s), %d CPUs, %d seconds, %d milliseconds, mem/max (%d/%d) """ \
|
||||
# % (nodeName, ostype, state, numVirtCpu, cpuTime/float(1000000000), cpuTime/float(1000000), memory, maxMem )
|
||||
print "%s.value %d" % (nodeName, cpuTime/float(1000000))
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue