diff options
author | Guido Günther <agx@sigxcpu.org> | 2008-10-21 18:12:59 +0200 |
---|---|---|
committer | Guido Guenther <agx@sigxcpu.org> | 2008-10-21 18:12:59 +0200 |
commit | f5ead05a9faba85618401b4f09c216addf9e354d (patch) | |
tree | 222856352a5390b2be0138b8cc7b8bc2e97fcc6a /libvirt-cputime | |
parent | 27b67971e7ebebd0b9ddc0ab8d4ca9c9b6ca52aa (diff) |
add cputime plugin
Diffstat (limited to 'libvirt-cputime')
-rw-r--r-- | libvirt-cputime | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/libvirt-cputime b/libvirt-cputime new file mode 100644 index 0000000..011a115 --- /dev/null +++ b/libvirt-cputime @@ -0,0 +1,76 @@ +#!/usr/bin/python +# vim: set fileencoding=utf-8 : +# +# Munin plugin to show the percent of cputime of libvirt managed virtual +# machines +# +# Copyright 2008 Guido Guenther <agx@sigxcpu.org> +# +# depends: python-libvirt +# +# If you don't want to use the default uri use: +# +# [libvirt-*] +# env.uri qemu:///system +# +# in your plugin configuration + +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 Cpu Time +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""" + + conn = libvirt.openReadOnly(uri) + ids = conn.listDomainsID() + for id in ids: + dom = conn.lookupByID(id) + name = dom.name() + print "%s_cputime.label %s" % (canon(name), name) + print "%s_cputime.type DERIVE" % canon(name) + print "%s_cputime.min 0" % canon(name) + + +def fetch_values(uri): + conn = libvirt.openReadOnly(uri) + ids = conn.listDomainsID() + + processors = float(conn.getInfo()[2]) + for id in ids: + dom = conn.lookupByID(id) + name = dom.name() + cputime = float(dom.info()[4]) + cputime_percentage = 1.0e-7 * cputime / processors + print "%s_cputime.value %.0f" % (canon(name), cputime_percentage) + + +def main(sys): + uri = os.getenv("uri") + + 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': + print_config(uri) + return 0 + fetch_values(uri) + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv)) + +# vim:et:ts=4:sw=4: |