munin-libvirtpy now in python3 (#1258)
* works on debian bullseye * flake8 compatiblity ckecked * print errors to file=sys.stderr
This commit is contained in:
parent
b76174718e
commit
367a4b3727
|
@ -1,57 +1,75 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Revision 1.0 2008/05/16 - Steven Wagner
|
||||
# First functional release. Works for me.
|
||||
#
|
||||
# Revision 0.5 2008/05/01 - Julien Rottenberg
|
||||
# initial display of variables from libvirt
|
||||
"""
|
||||
=encoding utf8
|
||||
|
||||
#python-libvirt is required
|
||||
=head1 NAME
|
||||
|
||||
munin-libvirtpy - KVM Domain CPU Utilization
|
||||
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
Parsed environment variables:
|
||||
python-libvirt is required
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv3
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
Julien Rottenberg
|
||||
|
||||
Steven Wagner
|
||||
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# capabilities=autoconf
|
||||
#%# family=contrib
|
||||
|
||||
=cut
|
||||
"""
|
||||
|
||||
import libvirt
|
||||
import sys
|
||||
|
||||
conn = libvirt.openReadOnly("qemu:///system")
|
||||
if conn == None:
|
||||
print 'Failed to open connection to the hypervisor'
|
||||
if conn is None:
|
||||
print('Failed to open connection to the hypervisor')
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
(model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo()
|
||||
except:
|
||||
print 'getInfo failed'
|
||||
except BaseException as error:
|
||||
print('getInfo failed: {}'.format(error), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
#print
|
||||
#print "KVM running on %d %s %d mhz CPUs w/ %d MB RAM." % (cpus, model, mhz, memory)
|
||||
#print
|
||||
|
||||
ids = conn.listDomainsID()
|
||||
if ids == None or len(ids) == 0:
|
||||
print 'No running domains found.'
|
||||
if ids is None or len(ids) == 0:
|
||||
print('No running domains found.', file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
if sys.argv[1] == "config":
|
||||
print "graph_title KVM Domain CPU Utilization"
|
||||
print "graph_vlabel CPU use in seconds"
|
||||
print "graph_args --base 1000"
|
||||
print "graph_category virtualization"
|
||||
print("graph_title KVM Domain CPU Utilization")
|
||||
print("graph_vlabel CPU use in seconds")
|
||||
print("graph_args --base 1000")
|
||||
print("graph_category virtualization")
|
||||
|
||||
for id in ids:
|
||||
dom = conn.lookupByID(id)
|
||||
nodeName = dom.name()
|
||||
print "%s.type COUNTER" %(nodeName)
|
||||
print "%s.label %s" %(nodeName, nodeName)
|
||||
print("%s.type COUNTER" % (nodeName))
|
||||
print("%s.label %s" % (nodeName, nodeName))
|
||||
sys.exit(0)
|
||||
|
||||
for id in ids:
|
||||
dom = conn.lookupByID(id)
|
||||
state, maxMem, memory, numVirtCpu, cpuTime = dom.info()
|
||||
nodeName = dom.name()
|
||||
# uuid = dom.UUID()
|
||||
# ostype = dom.OSType()
|
||||
# print """Domain: %s, %s state (%s), %d CPUs, %d seconds, %d milliseconds, mem/max (%d/%d) """ \
|
||||
# % (nodeName, ostype, state, numVirtCpu, cpuTime/float(1000000000), cpuTime/float(1000000), memory, maxMem )
|
||||
print "%s.value %d" % (nodeName, cpuTime/float(1000000))
|
||||
print("%s.value %d" % (nodeName, cpuTime/float(1000000)))
|
||||
|
|
Loading…
Reference in New Issue