source: trunk/packages/xvm-munin-config/host/usr/share/xvm-munin-host-config/plugins/xen_cpu @ 1777

Last change on this file since 1777 was 1777, checked in by quentin, 15 years ago

Munin Xen CPU utilization fixes

rrdtool and thus Munin can't handle floating point DERIVE or COUNTER sources, so convert to microseconds before passing to Munin.

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/usr/bin/python
2
3from xen.xm.main import SERVER_LEGACY_XMLRPC, SERVER_XEN_API, parseServer
4from xen.xend import sxp
5
6serverType, serverURI = parseServer()
7
8if serverType == SERVER_XEN_API:
9    from xen.xm import XenAPI
10    server = XenAPI.Session(serverURI)
11    username, password = parseAuthentication()
12    server.login_with_password(username, password)
13    def logout():
14        try:
15            server.xenapi.session.logout()
16        except:
17            pass
18    atexit.register(logout)
19else:
20    from xen.util.xmlrpcclient import ServerProxy
21    server = ServerProxy(serverURI)
22
23import sys
24
25if len(sys.argv) > 1:
26    cmd = sys.argv[1]
27else:
28    cmd = None
29
30def getDomains():
31    ret = {}
32    if serverType == SERVER_XEN_API:
33        domains = server.xenapu.VM.get_all_records()
34        metrics = server.xenapi.VM_metrics.get_all_records()
35        for d in domains.values():
36            ret[d['uuid'].replace('-', '_')] = {'name': d['name_label'],
37                                                'cpu_time': sum(metrics[d['metrics']]['VCPUs_utilisation'].values()),
38                                                'domid': d['domid'],
39                                                'uuid': d['uuid'],
40                                                }
41        return ret
42    else:
43        domains = server.xend.domains_with_state(True, 'all', True)
44        for d in domains:
45            ret[sxp.child_value(d, 'uuid', 'NONE').replace('-', '_')] = {'name': sxp.child_value(d, 'name', 'UNKNOWN'),
46                                                                         'cpu_time': sxp.child_value(d, 'cpu_time', 0.0),
47                                                                         'domid': sxp.child_value(d, 'domid', -1),
48                                                                         'uuid': sxp.child_value(d, 'uuid', 'NONE'),
49                                                                         }
50        return ret
51
52if cmd == 'config':
53    print """
54graph_title Xen domain CPU usage
55graph_args --base 1000 -r --lower-limit 0 --upper-limit 800
56graph_vlabel %
57graph_scale no
58graph_info This graph shows how CPU time is spent by Xen domains.
59graph_category system
60graph_period second"""
61    domains = getDomains()
62    for d in sorted(domains):
63        name = domains[d]['name']
64        if name[0:2] == 'd_':
65            name = 'user domain'
66        print "%s.label %s" % (d, name)
67        if domains[d]['domid'] == 0:
68            print "%s.draw AREA" % d
69        else:
70            print "%s.draw STACK" % d
71        print "%s.max 5000" % d
72        print "%s.min 0" % d
73        print "%s.type DERIVE" % d
74        print "%s.info %s" % (d, domains[d]['uuid'])
75        print "%s.cdef %s,10000,/" % (d, d)
76    sys.exit(0)
77
78domains = getDomains()
79for d in sorted(domains):
80    print "%s.value %s" % (d, long(domains[d]['cpu_time']*1000000))
Note: See TracBrowser for help on using the repository browser.