mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
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 changed files with 47 additions and 29 deletions
|
@ -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.
|
=encoding utf8
|
||||||
#
|
|
||||||
# Revision 0.5 2008/05/01 - Julien Rottenberg
|
|
||||||
# initial display of variables from libvirt
|
|
||||||
|
|
||||||
#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 libvirt
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
conn = libvirt.openReadOnly("qemu:///system")
|
conn = libvirt.openReadOnly("qemu:///system")
|
||||||
if conn == None:
|
if conn is None:
|
||||||
print 'Failed to open connection to the hypervisor'
|
print('Failed to open connection to the hypervisor')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo()
|
(model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo()
|
||||||
except:
|
except BaseException as error:
|
||||||
print 'getInfo failed'
|
print('getInfo failed: {}'.format(error), file=sys.stderr)
|
||||||
sys.exit(1)
|
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()
|
ids = conn.listDomainsID()
|
||||||
if ids == None or len(ids) == 0:
|
if ids is None or len(ids) == 0:
|
||||||
print 'No running domains found.'
|
print('No running domains found.', file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
if sys.argv[1] == "config":
|
if sys.argv[1] == "config":
|
||||||
print "graph_title KVM Domain CPU Utilization"
|
print("graph_title KVM Domain CPU Utilization")
|
||||||
print "graph_vlabel CPU use in seconds"
|
print("graph_vlabel CPU use in seconds")
|
||||||
print "graph_args --base 1000"
|
print("graph_args --base 1000")
|
||||||
print "graph_category virtualization"
|
print("graph_category virtualization")
|
||||||
|
|
||||||
for id in ids:
|
for id in ids:
|
||||||
dom = conn.lookupByID(id)
|
dom = conn.lookupByID(id)
|
||||||
nodeName = dom.name()
|
nodeName = dom.name()
|
||||||
print "%s.type COUNTER" %(nodeName)
|
print("%s.type COUNTER" % (nodeName))
|
||||||
print "%s.label %s" %(nodeName, nodeName)
|
print("%s.label %s" % (nodeName, nodeName))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
for id in ids:
|
for id in ids:
|
||||||
dom = conn.lookupByID(id)
|
dom = conn.lookupByID(id)
|
||||||
state, maxMem, memory, numVirtCpu, cpuTime = dom.info()
|
state, maxMem, memory, numVirtCpu, cpuTime = dom.info()
|
||||||
nodeName = dom.name()
|
nodeName = dom.name()
|
||||||
# uuid = dom.UUID()
|
print("%s.value %d" % (nodeName, cpuTime/float(1000000)))
|
||||||
# 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))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue