3 from xen.xm.main import SERVER_LEGACY_XMLRPC, SERVER_XEN_API, parseServer, parseAuthentication
4 from xen.xend import sxp
8 serverType, serverURI = parseServer()
10 if serverType != SERVER_LEGACY_XMLRPC:
11 print >>sys.stderr, "xen_cpu is untested with this Xen server type"
14 if serverType == SERVER_XEN_API:
15 from xen.xm import XenAPI
16 server = XenAPI.Session(serverURI)
17 username, password = parseAuthentication()
18 server.login_with_password(username, password)
21 server.xenapi.session.logout()
24 atexit.register(logout)
26 from xen.util.xmlrpcclient import ServerProxy
27 server = ServerProxy(serverURI)
36 if serverType == SERVER_XEN_API:
37 domains = server.xenapi.VM.get_all_records()
38 metrics = server.xenapi.VM_metrics.get_all_records()
39 for d in domains.values():
40 ret['uuid_'+d['uuid'].replace('-', '_')] = {'name': d['name_label'],
41 'cpu_time': sum(metrics[d['metrics']]['VCPUs_utilisation'].values()),
48 domains = server.xend.domains_with_state(True, 'all', True)
50 data = {'name': sxp.child_value(d, 'name', 'UNKNOWN'),
51 'cpu_time': sxp.child_value(d, 'cpu_time', 0.0),
52 'domid': sxp.child_value(d, 'domid', -1),
53 'uuid': sxp.child_value(d, 'uuid', 'NONE'),
56 sched = server.xend.domain.sched_credit_get(data['name'])
57 data['sched-credit'] = sched
59 data['sched-credit'] = None
60 ret['uuid_'+sxp.child_value(d, 'uuid', 'NONE').replace('-', '_')] = data
65 graph_title Xen domain CPU usage
66 graph_args --base 1000 -r --lower-limit 0 --upper-limit 800
69 graph_info This graph shows how CPU time is spent by Xen domains.
71 graph_period second"""
72 domains = getDomains()
73 for d in sorted(domains):
74 name = domains[d]['name']
76 name = 'db domid %d' % domains[d]['domid']
77 print "%s.label %s" % (d, name)
78 if domains[d]['domid'] == 0:
79 print "%s.draw AREA" % d
81 print "%s.draw STACK" % d
82 print "%s.max 19200000000" % d # 64x 100% CPU usage
84 print "%s.type DERIVE" % d
85 if domains[d].get('sched-credit'):
86 print "%s.info uuid %s CPU weight %d cap %d%%" % (d, domains[d]['uuid'], domains[d]['sched-credit']['weight'], domains[d]['sched-credit']['cap'])
88 print "%s.info uuid %s" % (d, domains[d]['uuid'])
89 print "%s.cdef %s,10000,/" % (d, d)
92 domains = getDomains()
93 for d in sorted(domains):
94 print "%s.value %s" % (d, long(domains[d]['cpu_time']*1000000))