From 725b681e1911b693ee3bbba56306e73bd43fa9ef Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Fri, 24 Oct 2008 13:17:38 +0200 Subject: calculate total used memory percentage don't display it, can be used for munin-limits --- libvirt-mem | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/libvirt-mem b/libvirt-mem index 950cd60..c7bf63d 100644 --- a/libvirt-mem +++ b/libvirt-mem @@ -21,19 +21,37 @@ def canon(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 + hostname = conn.getHostname() + + 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 +host_mem.label %(hostname)s (host) +host_mem.type GAUGE +host_mem.min 0 +host_mem.draw LINE1 +total.type GAUGE +total.label total +total.info memory used by virtual machines on host %(hostname)s +total.graph no +total.min 0 +total_pc.type GAUGE +total_pc.label used memory percentage +total_pc.info memory in percent used by virtual machines on host %(hostname)s +total_pc.graph no +total_pc.min 0 +total_pc.max 100 +total_pc.warning 90 +total_pc.critical 95""" % dict(hostname=hostname) + ids = conn.listDomainsID() draw = "AREA" for id in ids: @@ -45,16 +63,11 @@ graph_args --base 1024 -l 0""" 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): + total = 0 try: conn = libvirt.openReadOnly(uri) except libvirt.libvirtError, err: @@ -66,8 +79,11 @@ def fetch_values(uri): for id in ids: dom = conn.lookupByID(id) name = dom.name() - mem = float(dom.info()[2]) * 1024 + mem = dom.info()[2] * 1024 + total += mem print "%s_mem.value %d" % (canon(name), mem) + print "total.value %d" % total + print "total_pc.value %.0f" % (100.0 * total / float(hostmem)) return 0 -- cgit v1.2.3 From 310af9e9dc69e46c90d95ec8bf810d521fa53079 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Fri, 24 Oct 2008 13:18:02 +0200 Subject: calculate total used cputime percentage but don't display it - this way it can be used by munin-limits --- libvirt-cputime | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libvirt-cputime b/libvirt-cputime index 8758b17..86394ac 100644 --- a/libvirt-cputime +++ b/libvirt-cputime @@ -26,7 +26,15 @@ def print_config(uri, stack): graph_vlabel CPU Time percentage graph_category Virtual Machines graph_info This graph shows the cpu time percentage of each virtual machine -graph_args --base 1000 -l 0""" +graph_args --base 1000 -l 0 +total_pc.type DERIVE +total_pc.graph no +total_pc.min 0 +total_pc.max 100 +total_pc.label total +total_pc.info cputime used by all virtual machines +total_pc.warning 90 +total_pc.critical 95""" draw = [ "LINE1", "AREA"][stack] conn = libvirt.openReadOnly(uri) @@ -41,10 +49,10 @@ graph_args --base 1000 -l 0""" if draw == "AREA": draw = "STACK" - def fetch_values(uri): conn = libvirt.openReadOnly(uri) ids = conn.listDomainsID() + total = 0 processors = float(conn.getInfo()[2]) for id in ids: @@ -52,7 +60,9 @@ def fetch_values(uri): name = dom.name() cputime = float(dom.info()[4]) cputime_percentage = 1.0e-7 * cputime / processors + total += cputime_percentage print "%s_cputime.value %.0f" % (canon(name), cputime_percentage) + print "total_pc.value %.0f" % total def main(sys): -- cgit v1.2.3 From bc056f5982cf5fa10560f21aa34d231af84b514a Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 27 Oct 2008 20:08:04 +0100 Subject: add README --- INSTALL | 8 -------- README | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 README diff --git a/INSTALL b/INSTALL index 5228433..789eb9d 100644 --- a/INSTALL +++ b/INSTALL @@ -3,11 +3,3 @@ 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 </etc/munin/plugin-conf.d/libvirt -[libvirt-*] -env.uri xen:/// -EOF - diff --git a/README b/README new file mode 100644 index 0000000..cbb8ab0 --- /dev/null +++ b/README @@ -0,0 +1,23 @@ +This is a set of munin plugins to monitor virtual machines managed via libvirt. + +See INSTALL for installation instructions. + +The default uri used to connect to libvirt is "qemu:///system". This can be +changed in the plugin configuration: + +cat </etc/munin/plugin-conf.d/libvirt +[libvirt-*] +env.uri xen:/// +EOF + +libvirt-mem and libvirt-cputime support limits[1] for critical and warning +values. These are set to 90% (warning) and 95% (critical) by default. However +you can change them in /etc/munin/munin.conf: + +[somehost.example.com] +libvirt_cputime.total_pc.warning 60 +libvirt_cputime.total_pc.critical 75 +libvirt_mem.total_pc.warning 25 +libvirt_mem.total_pc.critical 50 + +[1]: http://munin.projects.linpro.no/wiki/HowToContact -- cgit v1.2.3 From 6d0909da57502ba90415a7e83fec8ffb427c0537 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 27 Oct 2008 20:16:43 +0100 Subject: bump version to 0.0.3 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f0a6d9a..64ef6b3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=0.0.2 +VERSION=0.0.3 PKG=munin-libvirt-plugins PLUGINDIR=/usr/share/munin/plugins/ -- cgit v1.2.3