3 from xen.xm.main import SERVER_LEGACY_XMLRPC, SERVER_XEN_API, parseServer
4 from xen.xend import sxp
6 serverType, serverURI = parseServer()
8 if 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)
15 server.xenapi.session.logout()
18 atexit.register(logout)
20 from xen.util.xmlrpcclient import ServerProxy
21 server = ServerProxy(serverURI)
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']] = {'name': d['name_label'],
37 'cpu_time': sum(metrics[d['metrics']]['VCPUs_utilisation'].values()),
42 domains = server.xend.domains_with_state(True, 'all', True)
44 ret[sxp.child_value(d, 'uuid', 'NONE')] = {'name': sxp.child_value(d, 'name', 'UNKNOWN'),
45 'cpu_time': sxp.child_value(d, 'cpu_time', 0.0),
46 'domid': sxp.child_value(d, 'domid', -1),
52 graph_title Xen domain CPU usage
53 graph_args --base 1000 -r --lower-limit 0 --upper-limit 800
56 graph_info This graph shows how CPU time is spent by Xen domains.
58 graph_period second"""
59 domains = getDomains()
60 for d in sorted(domains):
61 name = domains[d]['name']
64 print "%s.label %s" % (d, name)
65 if domains[d]['domid'] == 0:
66 print "%s.draw AREA" % d
68 print "%s.draw STACK" % d
69 print "%s.max 5000" % d
71 print "%s.type DERIVE" % d
72 print "%s.info %s" % (d, name)
75 domains = getDomains()
76 for d in sorted(domains):
77 print "%s.value %s" % (d, domains[d]['cpu_time'])