aboutsummaryrefslogtreecommitdiff
path: root/libvirt-ifstat
diff options
context:
space:
mode:
Diffstat (limited to 'libvirt-ifstat')
-rw-r--r--libvirt-ifstat43
1 files changed, 22 insertions, 21 deletions
diff --git a/libvirt-ifstat b/libvirt-ifstat
index 4fd2f93..c3b73fd 100644
--- a/libvirt-ifstat
+++ b/libvirt-ifstat
@@ -12,6 +12,7 @@
#%# capabilities=autoconf
#%# family=contrib
+from __future__ import print_function
import re, sys, os
import libvirt
import libxml2
@@ -22,10 +23,10 @@ def canon(name):
def print_config(uri):
"""print the plugin config, determine the domains"""
- print """graph_title Virtual Domain Network I/O
+ print("""graph_title Virtual Domain Network I/O
graph_vlabel Bytes rx (-)/ tx (+) per ${graph_period}
graph_category Virtual Machines
-graph_info This graph shows the network I/O of the virtual machines"""
+graph_info This graph shows the network I/O of the virtual machines""")
conn = libvirt.openReadOnly(uri)
ids = conn.listDomainsID()
@@ -33,21 +34,21 @@ graph_info This graph shows the network I/O of the virtual machines"""
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_rx.label %s" % (canon(name), name)
- print "%s_rx.type DERIVE" % canon(name)
- print "%s_rx.min 0" % canon(name)
- print "%s_rx.graph no" % canon(name)
- print "%s_rx.draw LINE1" % canon(name)
- print "%s_tx.label %s" % (canon(name), name)
- print "%s_tx.type DERIVE" % canon(name)
- print "%s_tx.min 0" % canon(name)
- print "%s_tx.negative %s_rx" % (canon(name), canon(name))
- print "%s_tx.draw LINE1" % canon(name)
+ print("%s_rx.label %s" % (canon(name), name))
+ print("%s_rx.type DERIVE" % canon(name))
+ print("%s_rx.min 0" % canon(name))
+ print("%s_rx.graph no" % canon(name))
+ print("%s_rx.draw LINE1" % canon(name))
+ print("%s_tx.label %s" % (canon(name), name))
+ print("%s_tx.type DERIVE" % canon(name))
+ print("%s_tx.min 0" % canon(name))
+ print("%s_tx.negative %s_rx" % (canon(name), canon(name)))
+ print("%s_tx.draw LINE1" % canon(name))
def get_ifaces(dom):
xml = dom.XMLDesc(0)
@@ -84,8 +85,8 @@ 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
@@ -96,9 +97,9 @@ def fetch_values(uri):
rd += stats[0]
wr += stats[4]
except TypeError:
- print >>sys.stderr, "Cannot get ifstats for '%s' on '%s'" % (iface, name)
- print "%s_rx.value %d" % (canon(name), rd)
- print "%s_tx.value %d" % (canon(name), wr)
+ print("Cannot get ifstats for '%s' on '%s'" % (iface, name), file=sys.stderr)
+ print("%s_rx.value %d" % (canon(name), rd))
+ print("%s_tx.value %d" % (canon(name), wr))
def main(sys):
@@ -107,10 +108,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)