aboutsummaryrefslogtreecommitdiff
path: root/libvirt-cputime
diff options
context:
space:
mode:
Diffstat (limited to 'libvirt-cputime')
-rw-r--r--libvirt-cputime31
1 files changed, 16 insertions, 15 deletions
diff --git a/libvirt-cputime b/libvirt-cputime
index f2d658d..a0af52c 100644
--- a/libvirt-cputime
+++ b/libvirt-cputime
@@ -13,6 +13,7 @@
#%# capabilities=autoconf
#%# family=contrib
+from __future__ import print_function
import re, sys, os
import libvirt
@@ -22,7 +23,7 @@ def canon(name):
def print_config(uri, stack):
"""print the plugin config, determine the domains"""
- print """graph_title Virtual Domain Cpu Time
+ 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
@@ -34,7 +35,7 @@ total_pc.max 100
total_pc.label total
total_pc.info cputime used by all virtual machines
total_pc.warning 90
-total_pc.critical 95"""
+total_pc.critical 95""")
draw = [ "LINE1", "AREA"][stack]
conn = libvirt.openReadOnly(uri)
@@ -43,16 +44,16 @@ total_pc.critical 95"""
try:
dom = conn.lookupByID(id)
name = dom.name()
- except libvirt.libvirtError, err:
- print >>sys.stderr, "Id: %s: %s" % (id, err)
+ except libvirt.libvirtError as err:
+ print("Id: %s: %s" % (id, err), file=sys.stderr)
continue
if name == "Domain-0":
continue
- print "%s_cputime.label %s" % (canon(name), name)
- print "%s_cputime.type DERIVE" % canon(name)
- print "%s_cputime.min 0" % canon(name)
- print "%s_cputime.draw %s" % (canon(name), draw)
- print "%s_cputime.info percent of cputime used by virtual machine '%s'" % (canon(name), name)
+ print("%s_cputime.label %s" % (canon(name), name))
+ print("%s_cputime.type DERIVE" % canon(name))
+ print("%s_cputime.min 0" % canon(name))
+ print("%s_cputime.draw %s" % (canon(name), draw))
+ print("%s_cputime.info percent of cputime used by virtual machine '%s'" % (canon(name), name))
if draw == "AREA":
draw = "STACK"
@@ -66,16 +67,16 @@ def fetch_values(uri):
try:
dom = conn.lookupByID(id)
name = dom.name()
- except libvirt.libvirtError, err:
- print >>sys.stderr, "Id: %s: %s" % (id, err)
+ except libvirt.libvirtError as err:
+ print("Id: %s: %s" % (id, err), file=sys.stderr)
continue
if name == "Domain-0":
continue
cputime = float(dom.info()[4])
cputime_percentage = 1.0e-7 * cputime / processors
total += cputime_percentage
- print "%s_cputime.value %.0f" % (canon(name), cputime_percentage)
- print "total_pc.value %.0f" % total
+ print("%s_cputime.value %.0f" % (canon(name), cputime_percentage))
+ print("total_pc.value %.0f" % total)
def main(sys):
@@ -85,10 +86,10 @@ def main(sys):
if len(sys) > 1:
if sys[1] in [ 'autoconf', 'detect' ]:
if libvirt.openReadOnly(uri):
- print "yes"
+ print("yes")
return 0
else:
- print "no"
+ print("no")
return 1
elif sys[1] == 'config':
print_config(uri, stack)