X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fvirt.c;h=64f9415dd43792769a0f217b1ba272a012eb4aba;hb=4436eed7d1b5e841a87604de85ff0267dfd1a631;hp=2a97df326fa508a3f85fb9cb4c61b70d04a0762e;hpb=fe5167843e22b7b1ca4c7e5ba0e1d0df387b0094;p=collectd.git diff --git a/src/virt.c b/src/virt.c index 2a97df32..64f9415d 100644 --- a/src/virt.c +++ b/src/virt.c @@ -611,7 +611,8 @@ enum ex_stats { ex_stats_disk_allocation = 1 << 10, ex_stats_disk_capacity = 1 << 11, ex_stats_disk_physical = 1 << 12, - ex_stats_memory = 1 << 13 + ex_stats_memory = 1 << 13, + ex_stats_vcpu = 1 << 14 }; static unsigned int extra_stats = ex_stats_none; @@ -643,6 +644,7 @@ static const struct ex_stats_item ex_stats_table[] = { {"disk_capacity", ex_stats_disk_capacity}, {"disk_physical", ex_stats_disk_physical}, {"memory", ex_stats_memory}, + {"vcpu", ex_stats_vcpu}, {NULL, ex_stats_none}, }; @@ -1587,7 +1589,6 @@ static void vcpu_pin_submit(virDomainPtr dom, int max_cpus, int vcpu, static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { int max_cpus = VIR_NODEINFO_MAXCPUS(nodeinfo); - int cpu_map_len = VIR_CPU_MAPLEN(max_cpus); virVcpuInfoPtr vinfo = calloc(nr_virt_cpu, sizeof(*vinfo)); if (vinfo == NULL) { @@ -1595,11 +1596,17 @@ static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { return -1; } - unsigned char *cpumaps = calloc(nr_virt_cpu, cpu_map_len); - if (cpumaps == NULL) { - ERROR(PLUGIN_NAME " plugin: calloc failed."); - sfree(vinfo); - return -1; + int cpu_map_len = 0; + unsigned char *cpumaps = NULL; + if (extra_stats & ex_stats_vcpupin) { + cpu_map_len = VIR_CPU_MAPLEN(max_cpus); + cpumaps = calloc(nr_virt_cpu, cpu_map_len); + + if (cpumaps == NULL) { + ERROR(PLUGIN_NAME " plugin: calloc failed."); + sfree(vinfo); + return -1; + } } int status = @@ -1613,7 +1620,8 @@ static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { } for (int i = 0; i < nr_virt_cpu; ++i) { - vcpu_submit(vinfo[i].cpuTime, domain, vinfo[i].number, "virt_vcpu"); + if (extra_stats & ex_stats_vcpu) + vcpu_submit(vinfo[i].cpuTime, domain, vinfo[i].number, "virt_vcpu"); if (extra_stats & ex_stats_vcpupin) vcpu_pin_submit(domain, max_cpus, i, cpumaps, cpu_map_len); } @@ -2020,7 +2028,8 @@ static int get_domain_metrics(domain_t *domain) { memory_submit(domain->ptr, (gauge_t)info.memory * 1024); - GET_STATS(get_vcpu_stats, "vcpu stats", domain->ptr, info.nrVirtCpu); + if (extra_stats & (ex_stats_vcpu | ex_stats_vcpupin)) + GET_STATS(get_vcpu_stats, "vcpu stats", domain->ptr, info.nrVirtCpu); if (extra_stats & ex_stats_memory) GET_STATS(get_memory_stats, "memory stats", domain->ptr);