Add xen_cpu plugin for monitoring domain CPU usage
authorQuentin Smith <quentin@mit.edu>
Tue, 25 Nov 2008 03:42:51 +0000 (22:42 -0500)
committerQuentin Smith <quentin@mit.edu>
Tue, 25 Nov 2008 03:42:51 +0000 (22:42 -0500)
svn path=/trunk/packages/xvm-munin-config/; revision=1765

debian/xvm-munin-host-config.postinst
host/etc/munin/plugin-conf.d/xen_cpu [new file with mode: 0644]
host/etc/munin/plugins/xen_cpu [new symlink]
host/usr/share/xvm-munin-host-config/plugins/xen_cpu [new file with mode: 0755]

index 5060710..ce981db 100755 (executable)
@@ -28,7 +28,7 @@ case "$1" in
 ### BEGIN xvm-munin-config
 munin ALL=(postfix) SETENV: NOPASSWD: /etc/munin/plugins/postfix_mailqueue
 munin ALL=(munin) SETENV: NOPASSWD: ALL
-munin ALL=(root) SETENV: NOPASSWD: /etc/munin/plugins/hddtemp_smartctl , /etc/munin/plugins/smart_*
+munin ALL=(root) SETENV: NOPASSWD: /etc/munin/plugins/hddtemp_smartctl , /etc/munin/plugins/smart_* , /etc/munin/plugins/xen_cpu
 ### END xvm-munin-config
 EOF
         
diff --git a/host/etc/munin/plugin-conf.d/xen_cpu b/host/etc/munin/plugin-conf.d/xen_cpu
new file mode 100644 (file)
index 0000000..79defca
--- /dev/null
@@ -0,0 +1,3 @@
+[xen_cpu]
+user root
+command sudo -E %c
diff --git a/host/etc/munin/plugins/xen_cpu b/host/etc/munin/plugins/xen_cpu
new file mode 120000 (symlink)
index 0000000..7a83328
--- /dev/null
@@ -0,0 +1 @@
+/usr/share/xvm-munin-host-config/plugins/xen_cpu
\ No newline at end of file
diff --git a/host/usr/share/xvm-munin-host-config/plugins/xen_cpu b/host/usr/share/xvm-munin-host-config/plugins/xen_cpu
new file mode 100755 (executable)
index 0000000..41472db
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/python
+
+from xen.xm.main import SERVER_LEGACY_XMLRPC, SERVER_XEN_API, parseServer
+from xen.xend import sxp
+
+serverType, serverURI = parseServer()
+
+if serverType == SERVER_XEN_API:
+    from xen.xm import XenAPI
+    server = XenAPI.Session(serverURI)
+    username, password = parseAuthentication()
+    server.login_with_password(username, password)
+    def logout():
+        try:
+            server.xenapi.session.logout()
+        except:
+            pass
+    atexit.register(logout)
+else:
+    from xen.util.xmlrpcclient import ServerProxy
+    server = ServerProxy(serverURI)
+
+import sys
+
+if len(sys.argv) > 1:
+    cmd = sys.argv[1]
+else:
+    cmd = None
+
+def getDomains():
+    ret = {}
+    if serverType == SERVER_XEN_API:
+        domains = server.xenapu.VM.get_all_records()
+        metrics = server.xenapi.VM_metrics.get_all_records()
+        for d in domains.values():
+            ret[d['uuid']] = {'name': d['name_label'],
+                              'cpu_time': sum(metrics[d['metrics']]['VCPUs_utilisation'].values()),
+                              'domid': d['domid'],
+                              }
+        return ret
+    else:
+        domains = server.xend.domains_with_state(True, 'all', True)
+        for d in domains:
+            ret[sxp.child_value(d, 'uuid', 'NONE')] = {'name': sxp.child_value(d, 'name', 'UNKNOWN'),
+                                                       'cpu_time': sxp.child_value(d, 'cpu_time', 0.0),
+                                                       'domid': sxp.child_value(d, 'domid', -1),
+                                                       }
+        return ret
+
+if cmd == 'config':
+    print """
+graph_title Xen domain CPU usage
+graph_args --base 1000 -r --lower-limit 0 --upper-limit 800
+graph_vlabel %
+graph_scale no
+graph_info This graph shows how CPU time is spent by Xen domains.
+graph_category system
+graph_period second"""
+    domains = getDomains()
+    for d in sorted(domains):
+        name = domains[d]['name']
+        if name[0:2] == 'd_':
+            name = 'user domain'
+        print "%s.label %s" % (d, name)
+        if domains[d]['domid'] == 0:
+            print "%s.draw AREA" % d
+        else:
+            print "%s.draw STACK" % d
+        print "%s.max 5000" % d
+        print "%s.min 0" % d
+        print "%s.type DERIVE" % d
+        print "%s.info %s" % (d, name)
+    sys.exit(0)
+
+domains = getDomains()
+for d in sorted(domains):
+    print "%s.value %s" % (d, domains[d]['cpu_time'])