root / plugins / virtualization / munin-libvirtpy @ 81db94e2
Historique | Voir | Annoter | Télécharger (1,64 ko)
| 1 |
#!/usr/bin/python |
|---|---|
| 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 |
| 8 |
|
| 9 |
#python-libvirt is required |
| 10 |
|
| 11 |
import libvirt |
| 12 |
import sys |
| 13 |
|
| 14 |
conn = libvirt.openReadOnly("qemu:///system")
|
| 15 |
if conn == None: |
| 16 |
print 'Failed to open connection to the hypervisor' |
| 17 |
sys.exit(1) |
| 18 |
|
| 19 |
try: |
| 20 |
(model, memory, cpus, mhz, nodes, socket, cores, threads) = conn.getInfo() |
| 21 |
except: |
| 22 |
print 'getInfo failed' |
| 23 |
sys.exit(1) |
| 24 |
|
| 25 |
|
| 26 |
#print "KVM running on %d %s %d mhz CPUs w/ %d MB RAM." % (cpus, model, mhz, memory) |
| 27 |
|
| 28 |
|
| 29 |
ids = conn.listDomainsID() |
| 30 |
if ids == None or len(ids) == 0: |
| 31 |
print 'No running domains found.' |
| 32 |
sys.exit(1) |
| 33 |
|
| 34 |
|
| 35 |
if len(sys.argv) == 2: |
| 36 |
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" |
| 41 |
|
| 42 |
for id in ids: |
| 43 |
dom = conn.lookupByID(id) |
| 44 |
nodeName = dom.name() |
| 45 |
print "%s.type COUNTER" %(nodeName) |
| 46 |
print "%s.label %s" %(nodeName, nodeName) |
| 47 |
sys.exit(1) |
| 48 |
|
| 49 |
for id in ids: |
| 50 |
dom = conn.lookupByID(id) |
| 51 |
state, maxMem, memory, numVirtCpu, cpuTime = dom.info() |
| 52 |
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)) |
| 58 |
|
| 59 |
|
