diff options
author | Guido Günther <agx@sigxcpu.org> | 2008-10-26 15:12:43 +0100 |
---|---|---|
committer | Guido Guenther <agx@sigxcpu.org> | 2008-10-26 15:12:43 +0100 |
commit | 71be47a2f36f300e39716a66ddc8a0e97708ef0a (patch) | |
tree | e848567100032560c1f54f5a28640987a49373bf | |
parent | 000f5030894886b09a4a98ccea539f6c6ca4ebab (diff) | |
parent | a54c85ac3ac8f5c2ad7de210ccfa53530a592f10 (diff) |
Merge commit '0.0.2' into debian
-rw-r--r-- | INSTALL | 13 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | libvirt-blkstat | 12 | ||||
-rw-r--r-- | libvirt-cputime | 19 | ||||
-rw-r--r-- | libvirt-ifstat | 12 | ||||
-rw-r--r-- | libvirt-mem | 92 |
6 files changed, 132 insertions, 28 deletions
@@ -0,0 +1,13 @@ +Installation is simple: + +make PLUGINDIR=/etc/munin/plugins install +/etc/init.d/munin-node restart + +The default uri used to connect to libvirt is "qemu:///system". This can be +changed in the plugin configuration: + +cat <<EOF >/etc/munin/plugin-conf.d/libvirt +[libvirt-*] +env.uri xen:/// +EOF + @@ -1,16 +1,18 @@ -VERSION=0.0.1 +VERSION=0.0.2 PKG=munin-libvirt-plugins +PLUGINDIR=/usr/share/munin/plugins/ PLUGINS=libvirt-cputime \ libvirt-blkstat \ - libvirt-ifstat + libvirt-ifstat \ + libvirt-mem -ALL=$(PLUGINS) Makefile COPYING +ALL=$(PLUGINS) Makefile COPYING INSTALL PYFILES=$(patsubst %,%.py,$(PLUGINS)) install: $(PLUGINS) - install -d $(DESTDIR)/usr/share/munin/plugins/ - install -m 755 $(PLUGINS) $(DESTDIR)/usr/share/munin/plugins + install -d $(DESTDIR)$(PLUGINDIR) + install -m 755 $(PLUGINS) $(DESTDIR)$(PLUGINDIR) %.py: % ln -s $< $@ diff --git a/libvirt-blkstat b/libvirt-blkstat index f066683..c88d8a4 100644 --- a/libvirt-blkstat +++ b/libvirt-blkstat @@ -9,12 +9,8 @@ # # depends: python-libvirt, python-libxml2 # -# If you don't want to use the default uri use: -# -# [libvirt-*] -# env.uri qemu:///system -# -# in your plugin configuration +#%# capabilities=autoconf +#%# family=contrib import re, sys, os import libvirt @@ -40,10 +36,12 @@ graph_info This graph shows the block device I/O of the virtual machines""" print "%s_read.type DERIVE" % canon(name) print "%s_read.min 0" % canon(name) print "%s_read.graph no" % canon(name) + print "%s_read.draw LINE1" % canon(name) print "%s_write.label %s" % (canon(name), name) print "%s_write.type DERIVE" % canon(name) print "%s_write.min 0" % canon(name) print "%s_write.negative %s_read" % (canon(name), canon(name)) + print "%s_write.draw LINE1" % canon(name) def get_disks(dom): xml = dom.XMLDesc(0) @@ -93,7 +91,7 @@ def fetch_values(uri): def main(sys): - uri = os.getenv("uri") + uri = os.getenv("uri", "qemu:///system") if len(sys) > 1: if sys[1] in [ 'autoconf', 'detect' ]: diff --git a/libvirt-cputime b/libvirt-cputime index 6566f9d..8758b17 100644 --- a/libvirt-cputime +++ b/libvirt-cputime @@ -10,12 +10,8 @@ # # depends: python-libvirt # -# If you don't want to use the default uri use: -# -# [libvirt-*] -# env.uri qemu:///system -# -# in your plugin configuration +#%# capabilities=autoconf +#%# family=contrib import re, sys, os import libvirt @@ -23,7 +19,7 @@ import libvirt def canon(name): return re.sub(r"[^a-zA-Z0-9_]", "_", name) -def print_config(uri): +def print_config(uri, stack): """print the plugin config, determine the domains""" print """graph_title Virtual Domain Cpu Time @@ -32,6 +28,7 @@ graph_category Virtual Machines graph_info This graph shows the cpu time percentage of each virtual machine graph_args --base 1000 -l 0""" + draw = [ "LINE1", "AREA"][stack] conn = libvirt.openReadOnly(uri) ids = conn.listDomainsID() for id in ids: @@ -40,6 +37,9 @@ graph_args --base 1000 -l 0""" print "%s_cputime.label %s" % (canon(name), name) print "%s_cputime.type DERIVE" % canon(name) print "%s_cputime.min 0" % canon(name) + print "%s_cputime.draw %s" % (canon(name), draw) + if draw == "AREA": + draw = "STACK" def fetch_values(uri): @@ -56,7 +56,8 @@ def fetch_values(uri): def main(sys): - uri = os.getenv("uri") + uri = os.getenv("uri", "qemu:///system") + stack = [ False, True ][os.getenv("stack") == "1"] if len(sys) > 1: if sys[1] in [ 'autoconf', 'detect' ]: @@ -67,7 +68,7 @@ def main(sys): print "no" return 1 elif sys[1] == 'config': - print_config(uri) + print_config(uri, stack) return 0 fetch_values(uri) return 0 diff --git a/libvirt-ifstat b/libvirt-ifstat index 8d3bde4..25ce452 100644 --- a/libvirt-ifstat +++ b/libvirt-ifstat @@ -9,12 +9,8 @@ # # depends: python-libvirt, python-libxml2 # -# If you don't want to use the default uri use: -# -# [libvirt-*] -# env.uri qemu:///system -# -# in your plugin configuration +#%# capabilities=autoconf +#%# family=contrib import re, sys, os import libvirt @@ -40,10 +36,12 @@ graph_info This graph shows the network I/O of the virtual machines""" print "%s_rx.type DERIVE" % canon(name) print "%s_rx.min 0" % canon(name) print "%s_rx.graph no" % canon(name) + print "%s_rx.draw LINE1" % canon(name) print "%s_tx.label %s" % (canon(name), name) print "%s_tx.type DERIVE" % canon(name) print "%s_tx.min 0" % canon(name) print "%s_tx.negative %s_rx" % (canon(name), canon(name)) + print "%s_tx.draw LINE1" % canon(name) def get_ifaces(dom): xml = dom.XMLDesc(0) @@ -92,7 +90,7 @@ def fetch_values(uri): def main(sys): - uri = os.getenv("uri") + uri = os.getenv("uri", "qemu:///system") if len(sys) > 1: if sys[1] in [ 'autoconf', 'detect' ]: diff --git a/libvirt-mem b/libvirt-mem new file mode 100644 index 0000000..950cd60 --- /dev/null +++ b/libvirt-mem @@ -0,0 +1,92 @@ +#!/usr/bin/python +# vim: set fileencoding=utf-8 : +# +# Munin plugin to show the amount of memory used by libvirt managed virtual +# machines +# +# Copyright 2008 Guido Guenther <agx@sigxcpu.org> +# +# License: GPLv2 +# +# depends: python-libvirt +# +#%# capabilities=autoconf +#%# family=contrib + +import re, sys, os +import libvirt + +def canon(name): + return re.sub(r"[^a-zA-Z0-9_]", "_", name) + +def print_config(uri): + """print the plugin config, determine the domains""" + + print """graph_title Virtual Domain Memory Usage +graph_vlabel Memory Usage / Bytes +graph_category Virtual Machines +graph_info This graph shows the current amount of memory used by each virtual machine +graph_args --base 1024 -l 0""" + + try: + conn = libvirt.openReadOnly(uri) + except libvirt.libvirtError, err: + print >>sys.stderr, "Error opening to %s connection: %s" % (uri, err) + return 1 + + ids = conn.listDomainsID() + draw = "AREA" + for id in ids: + dom = conn.lookupByID(id) + name = dom.name() + print "%s_mem.label %s" % (canon(name), name) + print "%s_mem.type GAUGE" % canon(name) + print "%s_mem.min 0" % canon(name) + print "%s_mem.draw %s" % (canon(name), draw) + if draw == "AREA": + draw = "STACK" + + hostname = conn.getHostname() + print "host_mem.label %s (host)" % hostname + print "host_mem.type GAUGE" + print "host_mem.min 0" + print "host_mem.draw LINE1" + return 0 + + +def fetch_values(uri): + try: + conn = libvirt.openReadOnly(uri) + except libvirt.libvirtError, err: + print >>sys.stderr, "Error opening to %s connection: %s" % (uri, err) + return 1 + ids = conn.listDomainsID() + hostmem = conn.getInfo()[1] * 1024 * 1024 + print "host_mem.value %d" % hostmem + for id in ids: + dom = conn.lookupByID(id) + name = dom.name() + mem = float(dom.info()[2]) * 1024 + print "%s_mem.value %d" % (canon(name), mem) + return 0 + + +def main(sys): + uri = os.getenv("uri", "qemu:///system") + + if len(sys) > 1: + if sys[1] in [ 'autoconf', 'detect' ]: + if libvirt.openReadOnly(uri): + print "yes" + return 0 + else: + print "no" + return 1 + elif sys[1] == 'config': + return print_config(uri) + return fetch_values(uri) + +if __name__ == "__main__": + sys.exit(main(sys.argv)) + +# vim:et:ts=4:sw=4: |