Munin Xen CPU utilization fixes
[invirt/packages/xvm-munin-config.git] / host / usr / share / xvm-munin-host-config / plugins / xen_cpu
index 41472db..ecb68be 100755 (executable)
@@ -33,18 +33,20 @@ def getDomains():
         domains = server.xenapu.VM.get_all_records()
         metrics = server.xenapi.VM_metrics.get_all_records()
         for d in domains.values():
-            ret[d['uuid']] = {'name': d['name_label'],
-                              'cpu_time': sum(metrics[d['metrics']]['VCPUs_utilisation'].values()),
-                              'domid': d['domid'],
-                              }
+            ret[d['uuid'].replace('-', '_')] = {'name': d['name_label'],
+                                                'cpu_time': sum(metrics[d['metrics']]['VCPUs_utilisation'].values()),
+                                                'domid': d['domid'],
+                                                'uuid': d['uuid'],
+                                                }
         return ret
     else:
         domains = server.xend.domains_with_state(True, 'all', True)
         for d in domains:
-            ret[sxp.child_value(d, 'uuid', 'NONE')] = {'name': sxp.child_value(d, 'name', 'UNKNOWN'),
-                                                       'cpu_time': sxp.child_value(d, 'cpu_time', 0.0),
-                                                       'domid': sxp.child_value(d, 'domid', -1),
-                                                       }
+            ret[sxp.child_value(d, 'uuid', 'NONE').replace('-', '_')] = {'name': sxp.child_value(d, 'name', 'UNKNOWN'),
+                                                                         'cpu_time': sxp.child_value(d, 'cpu_time', 0.0),
+                                                                         'domid': sxp.child_value(d, 'domid', -1),
+                                                                         'uuid': sxp.child_value(d, 'uuid', 'NONE'),
+                                                                         }
         return ret
 
 if cmd == 'config':
@@ -69,9 +71,10 @@ graph_period second"""
         print "%s.max 5000" % d
         print "%s.min 0" % d
         print "%s.type DERIVE" % d
-        print "%s.info %s" % (d, name)
+        print "%s.info %s" % (d, domains[d]['uuid'])
+        print "%s.cdef %s,10000,/" % (d, d)
     sys.exit(0)
 
 domains = getDomains()
 for d in sorted(domains):
-    print "%s.value %s" % (d, domains[d]['cpu_time'])
+    print "%s.value %s" % (d, long(domains[d]['cpu_time']*1000000))