Révision 367a4b37
munin-libvirtpy now in python3 (#1258)
- works on debian bullseye
- flake8 compatiblity ckecked
- print errors to file=sys.stderr
| plugins/libvirt/munin-libvirtpy | ||
|---|---|---|
| 1 |
#!/usr/bin/env python |
|
| 1 |
#!/usr/bin/env python3
|
|
| 2 | 2 |
|
| 3 |
# Revision 1.0 2008/05/16 - Steven Wagner |
|
| 4 |
# First functional release. Works for me. |
|
| 5 |
# |
|
| 6 |
# Revision 0.5 2008/05/01 - Julien Rottenberg |
|
| 7 |
# initial display of variables from libvirt |
|
| 3 |
""" |
|
| 4 |
=encoding utf8 |
|
| 8 | 5 |
|
| 9 |
#python-libvirt is required |
|
| 6 |
=head1 NAME |
|
| 7 |
|
|
| 8 |
munin-libvirtpy - KVM Domain CPU Utilization |
|
| 9 |
|
|
| 10 |
|
|
| 11 |
=head1 CONFIGURATION |
|
| 12 |
|
|
| 13 |
Parsed environment variables: |
|
| 14 |
python-libvirt is required |
|
| 15 |
|
|
| 16 |
=head1 LICENSE |
|
| 17 |
|
|
| 18 |
GPLv3 |
|
| 19 |
|
|
| 20 |
SPDX-License-Identifier: GPL-3.0-only |
|
| 21 |
|
|
| 22 |
|
|
| 23 |
=head1 AUTHORS |
|
| 24 |
|
|
| 25 |
Julien Rottenberg |
|
| 26 |
|
|
| 27 |
Steven Wagner |
|
| 28 |
|
|
| 29 |
|
|
| 30 |
=head1 MAGIC MARKERS |
|
| 31 |
|
|
| 32 |
#%# capabilities=autoconf |
|
| 33 |
#%# family=contrib |
|
| 34 |
|
|
| 35 |
=cut |
|
| 36 |
""" |
|
| 10 | 37 |
|
| 11 | 38 |
import libvirt |
| 12 | 39 |
import sys |
| 13 | 40 |
|
| 14 | 41 |
conn = libvirt.openReadOnly("qemu:///system")
|
| 15 |
if conn == None:
|
|
| 16 |
print 'Failed to open connection to the hypervisor'
|
|
| 42 |
if conn is None:
|
|
| 43 |
print('Failed to open connection to the hypervisor')
|
|
| 17 | 44 |
sys.exit(1) |
| 18 | 45 |
|
| 19 | 46 |
try: |
| 20 | 47 |
(model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo() |
| 21 |
except: |
|
| 22 |
print 'getInfo failed'
|
|
| 48 |
except BaseException as error:
|
|
| 49 |
print('getInfo failed: {}'.format(error), file=sys.stderr)
|
|
| 23 | 50 |
sys.exit(1) |
| 24 | 51 |
|
| 25 |
|
|
| 26 |
#print "KVM running on %d %s %d mhz CPUs w/ %d MB RAM." % (cpus, model, mhz, memory) |
|
| 27 |
|
|
| 28 |
|
|
| 29 | 52 |
ids = conn.listDomainsID() |
| 30 |
if ids == None or len(ids) == 0:
|
|
| 31 |
print 'No running domains found.'
|
|
| 53 |
if ids is None or len(ids) == 0:
|
|
| 54 |
print('No running domains found.', file=sys.stderr)
|
|
| 32 | 55 |
sys.exit(1) |
| 33 | 56 |
|
| 34 |
|
|
| 35 | 57 |
if len(sys.argv) == 2: |
| 36 | 58 |
if sys.argv[1] == "config": |
| 37 |
print "graph_title KVM Domain CPU Utilization"
|
|
| 38 |
print "graph_vlabel CPU use in seconds"
|
|
| 39 |
print "graph_args --base 1000"
|
|
| 40 |
print "graph_category virtualization"
|
|
| 59 |
print("graph_title KVM Domain CPU Utilization")
|
|
| 60 |
print("graph_vlabel CPU use in seconds")
|
|
| 61 |
print("graph_args --base 1000")
|
|
| 62 |
print("graph_category virtualization")
|
|
| 41 | 63 |
|
| 42 | 64 |
for id in ids: |
| 43 | 65 |
dom = conn.lookupByID(id) |
| 44 | 66 |
nodeName = dom.name() |
| 45 |
print "%s.type COUNTER" %(nodeName)
|
|
| 46 |
print "%s.label %s" %(nodeName, nodeName)
|
|
| 67 |
print("%s.type COUNTER" % (nodeName))
|
|
| 68 |
print("%s.label %s" % (nodeName, nodeName))
|
|
| 47 | 69 |
sys.exit(0) |
| 48 | 70 |
|
| 49 | 71 |
for id in ids: |
| 50 | 72 |
dom = conn.lookupByID(id) |
| 51 | 73 |
state, maxMem, memory, numVirtCpu, cpuTime = dom.info() |
| 52 | 74 |
nodeName = dom.name() |
| 53 |
# uuid = dom.UUID() |
|
| 54 |
# ostype = dom.OSType() |
|
| 55 |
# print """Domain: %s, %s state (%s), %d CPUs, %d seconds, %d milliseconds, mem/max (%d/%d) """ \ |
|
| 56 |
# % (nodeName, ostype, state, numVirtCpu, cpuTime/float(1000000000), cpuTime/float(1000000), memory, maxMem ) |
|
| 57 |
print "%s.value %d" % (nodeName, cpuTime/float(1000000)) |
|
| 75 |
print("%s.value %d" % (nodeName, cpuTime/float(1000000)))
|
|
Formats disponibles : Unified diff