"minor_fault", "unused", "available",
"actual_balloon", "rss"};
- if ((tag_index < 0) || (tag_index >= STATIC_ARRAY_SIZE(tags))) {
+ if ((tag_index < 0) || (tag_index >= (int)STATIC_ARRAY_SIZE(tags))) {
ERROR("virt plugin: Array index out of bounds: tag_index = %d", tag_index);
return;
}
}
}
-static unsigned int parse_ex_stats_flags(const char *exstats, int numexstats) {
- int extra_stats = ex_stats_none;
+static unsigned int parse_ex_stats_flags(char **exstats, int numexstats) {
+ unsigned int ex_stats_flags = ex_stats_none;
for (int i = 0; i < numexstats; i++) {
for (int j = 0; ex_stats_table[j].name != NULL; j++) {
if (strcasecmp(exstats[i], ex_stats_table[j].name) == 0) {
DEBUG(PLUGIN_NAME " plugin: enabling extra stats for '%s'",
ex_stats_table[j].name);
- extra_stats |= ex_stats_table[j].flag;
+ ex_stats_flags |= ex_stats_table[j].flag;
break;
}
}
}
- return extra_stats;
+ return ex_stats_flags;
}
static int lv_config(const char *key, const char *value) {
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]);
return 0;
}
+/*
+ virConnectListAllDomains() appeared in 0.10.2
+ Note that LIBVIR_CHECK_VERSION appeared a year later, so
+ in some systems which actually have virConnectListAllDomains()
+ we can't detect this.
+ */
+#ifdef LIBVIR_CHECK_VERSION
+# if LIBVIR_CHECK_VERSION(0,10,2)
+# define HAVE_LIST_ALL_DOMAINS 1
+# endif
+#endif
+
static int refresh_lists(struct lv_read_instance *inst) {
struct lv_read_state *state = &inst->read_state;
int n;
lv_clean_read_state(state);
if (n > 0) {
+#ifdef HAVE_LIST_ALL_DOMAINS
+ virDomainPtr *domains;
+ n = virConnectListAllDomains (conn, &domains, VIR_CONNECT_LIST_DOMAINS_ACTIVE);
+#else
int *domids;
/* Get list of domains. */
}
n = virConnectListDomains(conn, domids, n);
+#endif
+
if (n < 0) {
VIRT_ERROR(conn, "reading list of domains");
+#ifndef HAVE_LIST_ALL_DOMAINS
sfree(domids);
+#endif
return -1;
}
/* Fetch each domain and add it to the list, unless ignore. */
for (int i = 0; i < n; ++i) {
- virDomainPtr dom = NULL;
const char *name;
char *xml = NULL;
xmlDocPtr xml_doc = NULL;
xmlXPathContextPtr xpath_ctx = NULL;
xmlXPathObjectPtr xpath_obj = NULL;
char tag[PARTITION_TAG_MAX_LEN] = {'\0'};
+ virDomainInfo info;
+ int status;
+#ifdef HAVE_LIST_ALL_DOMAINS
+ virDomainPtr dom = domains[i];
+#else
+ virDomainPtr dom = NULL;
dom = virDomainLookupByID(conn, domids[i]);
if (dom == NULL) {
VIRT_ERROR(conn, "virDomainLookupByID");
/* Could be that the domain went away -- ignore it anyway. */
continue;
}
+#endif
name = virDomainGetName(dom);
if (name == NULL) {
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;
sfree(xml);
}
+#ifdef HAVE_LIST_ALL_DOMAINS
+ sfree (domains);
+#else
sfree(domids);
+#endif
}
DEBUG(PLUGIN_NAME " plugin#%s: refreshing"