virt: Add block info statistics for block devices
authorRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Mon, 25 Jun 2018 12:30:57 +0000 (13:30 +0100)
committerRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Wed, 23 Jan 2019 13:33:31 +0000 (13:33 +0000)
virDomainBlockInfo statistics are now exposed through virt
plugin as:
-disk_allocation
-disk_capacity
-disk_physical

Those statistics are optional. They can be enabled by adding
corresponding entries to ExtraStats section in virt plugin
configuration in collectd.conf.

New ExtraStats are:
-'disk_allocation'
-'disk_capacity'
-'disk_physical'

Change-Id: I75475eca8b9eb402a894e2ae3c70c8b09b0eed9a
Signed-off-by: Radoslaw Jablonski <radoslawx.jablonski@intel.com>
src/collectd.conf.in
src/collectd.conf.pod
src/types.db
src/virt.c

index f58d3b4..0bcf382 100644 (file)
 #      InterfaceFormat name
 #      PluginInstanceFormat name
 #      Instances 1
-#      ExtraStats "cpu_util disk disk_err domain_state fs_info job_stats_background pcpu perf vcpupin"
+#      ExtraStats "cpu_util disk disk_err domain_state fs_info job_stats_background pcpu perf vcpupin disk_physical disk_allocation disk_capacity"
 #      PersistentNotification false
 #</Plugin>
 
index bb31e02..3c1efec 100644 (file)
@@ -9414,6 +9414,18 @@ B<Note>: I<perf> metrics can't be collected if I<intel_rdt> plugin is enabled.
 
 =item B<vcpupin>: report pinning of domain VCPUs to host physical CPUs.
 
+=item B<disk_physical>: report 'disk_physical' statistic for disk device.
+B<Note>: This statistic is only reported for disk devices with 'source'
+property available.
+
+=item B<disk_allocation>: report 'disk_allocation' statistic for disk device.
+B<Note>: This statistic is only reported for disk devices with 'source'
+property available.
+
+=item B<disk_capacity>: report 'disk_capacity' statistic for disk device.
+B<Note>: This statistic is only reported for disk devices with 'source'
+property available.
+
 =back
 
 =item B<PersistentNotification> B<true>|B<false>
index e9de64f..69f59b0 100644 (file)
@@ -51,6 +51,8 @@ df                      used:GAUGE:0:1125899906842623, free:GAUGE:0:112589990684
 df_complex              value:GAUGE:0:U
 df_inodes               value:GAUGE:0:U
 dilution_of_precision   value:GAUGE:0:U
+disk_allocation         value:GAUGE:0:U
+disk_capacity           value:GAUGE:0:U
 disk_error              value:GAUGE:0:U
 disk_io_time            io_time:DERIVE:0:U, weighted_io_time:DERIVE:0:U
 disk_latency            read:GAUGE:0:U, write:GAUGE:0:U
@@ -58,6 +60,7 @@ disk_merged             read:DERIVE:0:U, write:DERIVE:0:U
 disk_octets             read:DERIVE:0:U, write:DERIVE:0:U
 disk_ops                read:DERIVE:0:U, write:DERIVE:0:U
 disk_ops_complex        value:DERIVE:0:U
+disk_physical           value:GAUGE:0:U
 disk_time               read:DERIVE:0:U, write:DERIVE:0:U
 dns_answer              value:DERIVE:0:U
 dns_notify              value:DERIVE:0:U
index 41015fd..a6f050d 100644 (file)
@@ -617,6 +617,9 @@ enum ex_stats {
   ex_stats_job_stats_completed = 1 << 8,
   ex_stats_job_stats_background = 1 << 9,
 #endif
+  ex_stats_disk_allocation = 1 << 10,
+  ex_stats_disk_capacity = 1 << 11,
+  ex_stats_disk_physical = 1 << 12
 };
 
 static unsigned int extra_stats = ex_stats_none;
@@ -644,6 +647,9 @@ static const struct ex_stats_item ex_stats_table[] = {
     {"job_stats_completed", ex_stats_job_stats_completed},
     {"job_stats_background", ex_stats_job_stats_background},
 #endif
+    {"disk_allocation", ex_stats_disk_allocation},
+    {"disk_capacity", ex_stats_disk_capacity},
+    {"disk_physical", ex_stats_disk_physical},
     {NULL, ex_stats_none},
 };
 
@@ -682,6 +688,12 @@ static void init_block_stats(struct lv_block_stats *bstats) {
   bstats->fl_total_times = -1;
 }
 
+static void init_block_info(virDomainBlockInfoPtr binfo) {
+  binfo->allocation = -1;
+  binfo->capacity = -1;
+  binfo->physical = -1;
+}
+
 #ifdef HAVE_BLOCK_STATS_FLAGS
 
 #define GET_BLOCK_STATS_VALUE(NAME, FIELD)                                     \
@@ -1004,7 +1016,8 @@ static void vcpu_submit(derive_t value, virDomainPtr dom, int vcpu_nr,
 }
 
 static void disk_block_stats_submit(struct lv_block_stats *bstats,
-                                    virDomainPtr dom, const char *dev) {
+                                    virDomainPtr dom, const char *dev,
+                                    virDomainBlockInfoPtr binfo) {
   char *dev_copy = strdup(dev);
   const char *type_instance = dev_copy;
 
@@ -1046,6 +1059,20 @@ static void disk_block_stats_submit(struct lv_block_stats *bstats,
     }
   }
 
+  /* disk_allocation, disk_capacity and disk_physical are stored only
+   * if corresponding extrastats are set in collectd configuration file */
+  if ((extra_stats & ex_stats_disk_allocation) && binfo->allocation != -1)
+    submit(dom, "disk_allocation", type_instance,
+           &(value_t){.gauge = (gauge_t)binfo->allocation}, 1);
+
+  if ((extra_stats & ex_stats_disk_capacity) && binfo->capacity != -1)
+    submit(dom, "disk_capacity", type_instance,
+           &(value_t){.gauge = (gauge_t)binfo->capacity}, 1);
+
+  if ((extra_stats & ex_stats_disk_physical) && binfo->physical != -1)
+    submit(dom, "disk_physical", type_instance,
+           &(value_t){.gauge = (gauge_t)binfo->physical}, 1);
+
   sfree(dev_copy);
 }
 
@@ -1691,12 +1718,24 @@ 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;
+    }
+  }
+
   struct lv_block_stats bstats;
   init_block_stats(&bstats);
 
@@ -1705,7 +1744,7 @@ static int get_block_device_stats(struct block_device *block_dev) {
     return -1;
   }
 
-  disk_block_stats_submit(&bstats, block_dev->dom, block_dev->path);
+  disk_block_stats_submit(&bstats, block_dev->dom, block_dev->path, &binfo);
   return 0;
 }