X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibvirt.c;h=87b71e698b93c894a3c4cdabde0e218144ed083d;hb=b6fbfb1b864be53e71d755fba59d633f5c30da7e;hp=c53a81d4b5d1e4261667954b079d26e36a797e07;hpb=defd9a4014a34640b1228bbcb96e6aa99e8bbb37;p=collectd.git diff --git a/src/libvirt.c b/src/libvirt.c index c53a81d4..87b71e69 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -178,6 +178,25 @@ init_value_list (value_list_t *vl, virDomainPtr dom) } /* void init_value_list */ static void +memory_submit (gauge_t memory, virDomainPtr dom) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + init_value_list (&vl, dom); + + values[0].gauge = memory; + + vl.values = values; + vl.values_len = 1; + + sstrncpy (vl.type, "memory", sizeof (vl.type)); + sstrncpy (vl.type_instance, "total", sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} + +static void cpu_submit (unsigned long long cpu_time, virDomainPtr dom, const char *type) { @@ -407,7 +426,7 @@ lv_read (void) interface_devices[i].path); #endif - /* Get CPU usage, VCPU usage for each domain. */ + /* Get CPU usage, memory, VCPU usage for each domain. */ for (i = 0; i < nr_domains; ++i) { virDomainInfo info; virVcpuInfoPtr vinfo = NULL; @@ -422,7 +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 ((gauge_t) info.memory * 1024, domains[i]); vinfo = malloc (info.nrVirtCpu * sizeof (vinfo[0])); if (vinfo == NULL) {