From: Tiago Carvalho Date: Sun, 28 Apr 2013 20:36:48 +0000 (+0100) Subject: Included memory usage per VM X-Git-Tag: collectd-5.5.0~237^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=627a050790;p=collectd.git Included memory usage per VM Included all the metrics about the actual memory used by VMs (as returned by libvirt.virDomainMemoryStats) --- diff --git a/src/libvirt.c b/src/libvirt.c index cfabaaa2..849cfe22 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -196,6 +196,28 @@ memory_submit (gauge_t memory, virDomainPtr dom) plugin_dispatch_values (&vl); } +static void +memory_stats_submit (gauge_t memory, virDomainPtr dom, int tag_index) +{ + static const char *tags[] = { "swap_in", "swap_out", "major_fault", "minor_fault", + "unused", "available", "actual_balloon", "rss"}; + + 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, tags[tag_index], sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} + static void cpu_submit (unsigned long long cpu_time, virDomainPtr dom, const char *type) @@ -430,6 +452,7 @@ lv_read (void) for (i = 0; i < nr_domains; ++i) { virDomainInfo info; virVcpuInfoPtr vinfo = NULL; + virDomainMemoryStatPtr minfo = NULL; int status; int j; @@ -464,9 +487,30 @@ lv_read (void) vcpu_submit (vinfo[j].cpuTime, domains[i], vinfo[j].number, "virt_vcpu"); + + minfo = malloc (VIR_DOMAIN_MEMORY_STAT_NR * sizeof (virDomainMemoryStatStruct)); + if (minfo == NULL) { + ERROR ("libvirt plugin: malloc failed."); + continue; + } + + status = virDomainMemoryStats (domains[i], minfo, VIR_DOMAIN_MEMORY_STAT_NR, 0); + + if (status < 0) { + ERROR ("libvirt plugin: virDomainMemoryStats failed with status %i.", + status); + continue; + } + + for (j = 0; j < status; j++) { + memory_stats_submit ((gauge_t) minfo[j].val, domains[i], minfo[j].tag); + } + + sfree (minfo); sfree (vinfo); } + /* Get block device stats for each domain. */ for (i = 0; i < nr_block_devices; ++i) { struct _virDomainBlockStats stats;