Merge pull request #2874 from elfiesmelfie/feat_virt_block_info
[collectd.git] / src / virt.c
index a6f050d..2f64b50 100644 (file)
 
 #include "collectd.h"
 
-#include "common.h"
 #include "plugin.h"
+#include "utils/common/common.h"
+#include "utils/ignorelist/ignorelist.h"
 #include "utils_complain.h"
-#include "utils_ignorelist.h"
 
 #include <libgen.h> /* for basename(3) */
 #include <libvirt/libvirt.h>
@@ -735,7 +735,7 @@ static int get_block_stats(struct lv_block_stats *bstats,
       ERROR(PLUGIN_NAME " plugin: %s failed: %s", (s), err->message);          \
   } while (0)
 
-char *metadata_get_hostname(virDomainPtr dom) {
+static char *metadata_get_hostname(virDomainPtr dom) {
   const char *xpath_str = NULL;
   if (hm_xpath == NULL)
     xpath_str = "/instance/name/text()";
@@ -1718,21 +1718,26 @@ static int get_disk_err(virDomainPtr domain) {
 #endif /* HAVE_DISK_ERR */
 
 static int get_block_device_stats(struct block_device *block_dev) {
-  virDomainBlockInfo binfo;
-  init_block_info(&binfo);
-
   if (!block_dev) {
     ERROR(PLUGIN_NAME " plugin: get_block_stats NULL pointer");
     return -1;
   }
 
-  /* Block info statistics can be only fetched from devices with 'source'
-   * defined */
-  if (block_dev->has_source) {
-    if (virDomainGetBlockInfo(block_dev->dom, block_dev->path, &binfo, 0) < 0) {
-      ERROR(PLUGIN_NAME " plugin: virDomainGetBlockInfo failed for path: %s",
-            block_dev->path);
-      return -1;
+  virDomainBlockInfo binfo;
+  init_block_info(&binfo);
+
+  /* Fetching block info stats only if needed*/
+  if (extra_stats & (ex_stats_disk_allocation | ex_stats_disk_capacity |
+                     ex_stats_disk_physical)) {
+    /* Block info statistics can be only fetched from devices with 'source'
+     * defined */
+    if (block_dev->has_source) {
+      if (virDomainGetBlockInfo(block_dev->dom, block_dev->path, &binfo, 0) <
+          0) {
+        ERROR(PLUGIN_NAME " plugin: virDomainGetBlockInfo failed for path: %s",
+              block_dev->path);
+        return -1;
+      }
     }
   }