From 47a1feb037593b2572794cee1aa8052c9bcb05a7 Mon Sep 17 00:00:00 2001 From: Igor Pavlikevich Date: Thu, 9 Feb 2017 16:07:13 +0300 Subject: [PATCH] virt plugin: fix skipping inactive domains Remove inactive domains from domains list, not only in CPU/Memory/VCPU usage accounting Signed-off-by: Igor Pavlikevich --- src/virt.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/virt.c b/src/virt.c index 51682993..692088c4 100644 --- a/src/virt.c +++ b/src/virt.c @@ -824,11 +824,6 @@ static int lv_read(user_data_t *ud) { continue; } - if (info.di.state != VIR_DOMAIN_RUNNING) { - /* only gather stats for running domains */ - continue; - } - pcpu_submit(state->domains[i], &info); cpu_submit(info.di.cpuTime, state->domains[i], "virt_cpu_total"); memory_submit((gauge_t)info.di.memory * 1024, state->domains[i]); @@ -1129,6 +1124,8 @@ static int refresh_lists(struct lv_read_instance *inst) { xmlXPathContextPtr xpath_ctx = NULL; xmlXPathObjectPtr xpath_obj = NULL; char tag[PARTITION_TAG_MAX_LEN] = {'\0'}; + virDomainInfo info; + int status; dom = virDomainLookupByID(conn, domids[i]); if (dom == NULL) { @@ -1143,6 +1140,18 @@ static int refresh_lists(struct lv_read_instance *inst) { goto cont; } + status = virDomainGetInfo(dom, &info); + if (status != 0) { + ERROR(PLUGIN_NAME " plugin: virDomainGetInfo failed with status %i.", + status); + continue; + } + + if (info.state != VIR_DOMAIN_RUNNING) { + DEBUG(PLUGIN_NAME " plugin: skipping inactive domain %s", name); + continue; + } + if (il_domains && ignorelist_match(il_domains, name) != 0) goto cont; -- 2.11.0