root / plugins / libvirt / munin-libvirtpy @ 367a4b37
Historique | Voir | Annoter | Télécharger (1,5 ko)
| 1 |
#!/usr/bin/env python3 |
|---|---|
| 2 |
|
| 3 |
""" |
| 4 |
=encoding utf8 |
| 5 |
|
| 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 |
""" |
| 37 |
|
| 38 |
import libvirt |
| 39 |
import sys |
| 40 |
|
| 41 |
conn = libvirt.openReadOnly("qemu:///system")
|
| 42 |
if conn is None: |
| 43 |
print('Failed to open connection to the hypervisor')
|
| 44 |
sys.exit(1) |
| 45 |
|
| 46 |
try: |
| 47 |
(model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo() |
| 48 |
except BaseException as error: |
| 49 |
print('getInfo failed: {}'.format(error), file=sys.stderr)
|
| 50 |
sys.exit(1) |
| 51 |
|
| 52 |
ids = conn.listDomainsID() |
| 53 |
if ids is None or len(ids) == 0: |
| 54 |
print('No running domains found.', file=sys.stderr)
|
| 55 |
sys.exit(1) |
| 56 |
|
| 57 |
if len(sys.argv) == 2: |
| 58 |
if sys.argv[1] == "config": |
| 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")
|
| 63 |
|
| 64 |
for id in ids: |
| 65 |
dom = conn.lookupByID(id) |
| 66 |
nodeName = dom.name() |
| 67 |
print("%s.type COUNTER" % (nodeName))
|
| 68 |
print("%s.label %s" % (nodeName, nodeName))
|
| 69 |
sys.exit(0) |
| 70 |
|
| 71 |
for id in ids: |
| 72 |
dom = conn.lookupByID(id) |
| 73 |
state, maxMem, memory, numVirtCpu, cpuTime = dom.info() |
| 74 |
nodeName = dom.name() |
| 75 |
print("%s.value %d" % (nodeName, cpuTime/float(1000000)))
|
