76 lines
1.5 KiB
Python
Executable File
76 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""
|
|
=encoding utf8
|
|
|
|
=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 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 BaseException as error:
|
|
print('getInfo failed: {}'.format(error), file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
ids = conn.listDomainsID()
|
|
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")
|
|
|
|
for id in ids:
|
|
dom = conn.lookupByID(id)
|
|
nodeName = dom.name()
|
|
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()
|
|
print("%s.value %d" % (nodeName, cpuTime/float(1000000)))
|