statsd: provide a gauge for counters, holding the absolute count.
[collectd.git] / src / libvirt.c
index 6b0cf9a..6a397db 100644 (file)
@@ -178,7 +178,7 @@ init_value_list (value_list_t *vl, virDomainPtr dom)
 } /* void init_value_list */
 
 static void
-memory_submit (unsigned long memory, virDomainPtr dom, const char *type)
+memory_submit (gauge_t memory, virDomainPtr dom)
 {
     value_t values[1];
     value_list_t vl = VALUE_LIST_INIT;
@@ -190,7 +190,8 @@ memory_submit (unsigned long memory, virDomainPtr dom, const char *type)
     vl.values = values;
     vl.values_len = 1;
 
-    sstrncpy (vl.type, type, sizeof (vl.type));
+    sstrncpy (vl.type, "memory", sizeof (vl.type));
+    sstrncpy (vl.type_instance, "total", sizeof (vl.type_instance));
 
     plugin_dispatch_values (&vl);
 }
@@ -440,8 +441,14 @@ lv_read (void)
             continue;
         }
 
+        if (info.state != VIR_DOMAIN_RUNNING)
+        {
+            /* only gather stats for running domains */
+            continue;
+        }
+
         cpu_submit (info.cpuTime, domains[i], "virt_cpu_total");
-       memory_submit (info.memory, domains[i], "memory");
+        memory_submit ((gauge_t) info.memory * 1024, domains[i]);
 
         vinfo = malloc (info.nrVirtCpu * sizeof (vinfo[0]));
         if (vinfo == NULL) {
@@ -791,6 +798,9 @@ add_interface_device (virDomainPtr dom, const char *path, const char *address, u
     int new_size = sizeof (interface_devices[0]) * (nr_interface_devices+1);
     char *path_copy, *address_copy, number_string[15];
 
+    if ((path == NULL) || (address == NULL))
+        return EINVAL;
+
     path_copy = strdup (path);
     if (!path_copy) return -1;
 
@@ -826,6 +836,9 @@ ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath)
     char *name;
     int n, r;
 
+    if ((domname == NULL) || (devpath == NULL))
+        return 0;
+
     n = sizeof (char) * (strlen (domname) + strlen (devpath) + 2);
     name = malloc (n);
     if (name == NULL) {