From 055c714460257cd2b09f7d23aea4a300abe809ab Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johan=20Wir=C3=A9n?= Date: Wed, 6 Feb 2013 23:37:00 +0100 Subject: [PATCH] libvirt: Added support for memory allocation --- README | 2 +- src/libvirt.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README b/README index a8ec07b0..77ea6ff2 100644 --- a/README +++ b/README @@ -133,7 +133,7 @@ Features technique built into IBM's POWER processors. - libvirt - CPU, disk and network I/O statistics from virtual machines. + CPU, memory, disk and network I/O statistics from virtual machines. - madwifi Queries very detailed usage statistics from wireless LAN adapters and diff --git a/src/libvirt.c b/src/libvirt.c index c53a81d4..6b0cf9a4 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -177,6 +177,24 @@ init_value_list (value_list_t *vl, virDomainPtr dom) vl->host[sizeof (vl->host) - 1] = '\0'; } /* void init_value_list */ +static void +memory_submit (unsigned long memory, virDomainPtr dom, const char *type) +{ + 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, type, sizeof (vl.type)); + + plugin_dispatch_values (&vl); +} + static void cpu_submit (unsigned long long cpu_time, virDomainPtr dom, const char *type) @@ -407,7 +425,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; @@ -423,6 +441,7 @@ lv_read (void) } cpu_submit (info.cpuTime, domains[i], "virt_cpu_total"); + memory_submit (info.memory, domains[i], "memory"); vinfo = malloc (info.nrVirtCpu * sizeof (vinfo[0])); if (vinfo == NULL) { -- 2.30.2