aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido G√ľnther <agx@sigxcpu.org>2008-10-24 13:17:38 +0200
committerGuido Guenther <agx@sigxcpu.org>2008-10-24 14:07:48 +0200
commit725b681e1911b693ee3bbba56306e73bd43fa9ef (patch)
tree094f92c1d98520f3f5940368751007c81ca44afb
parenta54c85ac3ac8f5c2ad7de210ccfa53530a592f10 (diff)
calculate total used memory percentage
don't display it, can be used for munin-limits
-rw-r--r--libvirt-mem44
1 files changed, 30 insertions, 14 deletions
diff --git a/libvirt-mem b/libvirt-mem
index 950cd60..c7bf63d 100644
--- a/libvirt-mem
+++ b/libvirt-mem
@@ -21,19 +21,37 @@ def canon(name):
def print_config(uri):
"""print the plugin config, determine the domains"""
-
- print """graph_title Virtual Domain Memory Usage
-graph_vlabel Memory Usage / Bytes
-graph_category Virtual Machines
-graph_info This graph shows the current amount of memory used by each virtual machine
-graph_args --base 1024 -l 0"""
-
try:
conn = libvirt.openReadOnly(uri)
except libvirt.libvirtError, err:
print >>sys.stderr, "Error opening to %s connection: %s" % (uri, err)
return 1
+ hostname = conn.getHostname()
+
+ print """graph_title Virtual Domain Memory Usage
+graph_vlabel Memory Usage / Bytes
+graph_category Virtual Machines
+graph_info This graph shows the current amount of memory used by each virtual machine
+graph_args --base 1024 -l 0
+host_mem.label %(hostname)s (host)
+host_mem.type GAUGE
+host_mem.min 0
+host_mem.draw LINE1
+total.type GAUGE
+total.label total
+total.info memory used by virtual machines on host %(hostname)s
+total.graph no
+total.min 0
+total_pc.type GAUGE
+total_pc.label used memory percentage
+total_pc.info memory in percent used by virtual machines on host %(hostname)s
+total_pc.graph no
+total_pc.min 0
+total_pc.max 100
+total_pc.warning 90
+total_pc.critical 95""" % dict(hostname=hostname)
+
ids = conn.listDomainsID()
draw = "AREA"
for id in ids:
@@ -45,16 +63,11 @@ graph_args --base 1024 -l 0"""
print "%s_mem.draw %s" % (canon(name), draw)
if draw == "AREA":
draw = "STACK"
-
- hostname = conn.getHostname()
- print "host_mem.label %s (host)" % hostname
- print "host_mem.type GAUGE"
- print "host_mem.min 0"
- print "host_mem.draw LINE1"
return 0
def fetch_values(uri):
+ total = 0
try:
conn = libvirt.openReadOnly(uri)
except libvirt.libvirtError, err:
@@ -66,8 +79,11 @@ def fetch_values(uri):
for id in ids:
dom = conn.lookupByID(id)
name = dom.name()
- mem = float(dom.info()[2]) * 1024
+ mem = dom.info()[2] * 1024
+ total += mem
print "%s_mem.value %d" % (canon(name), mem)
+ print "total.value %d" % total
+ print "total_pc.value %.0f" % (100.0 * total / float(hostmem))
return 0