From 04d9e221d31f38d80acfff48c611b1fee5f830f4 Mon Sep 17 00:00:00 2001 From: Radoslaw Jablonski Date: Mon, 25 Jun 2018 13:30:57 +0100 Subject: [PATCH] virt: Add block info statistics for block devices 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 --- src/collectd.conf.in | 2 +- src/collectd.conf.pod | 12 ++++++++++++ src/types.db | 3 +++ src/virt.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index f58d3b49..0bcf3822 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1677,7 +1677,7 @@ # 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 # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index bb31e024..3c1efec7 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -9414,6 +9414,18 @@ B: I metrics can't be collected if I plugin is enabled. =item B: report pinning of domain VCPUs to host physical CPUs. +=item B: report 'disk_physical' statistic for disk device. +B: This statistic is only reported for disk devices with 'source' +property available. + +=item B: report 'disk_allocation' statistic for disk device. +B: This statistic is only reported for disk devices with 'source' +property available. + +=item B: report 'disk_capacity' statistic for disk device. +B: This statistic is only reported for disk devices with 'source' +property available. + =back =item B B|B diff --git a/src/types.db b/src/types.db index e9de64fc..69f59b06 100644 --- a/src/types.db +++ b/src/types.db @@ -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 diff --git a/src/virt.c b/src/virt.c index 41015fd4..a6f050d4 100644 --- a/src/virt.c +++ b/src/virt.c @@ -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; } -- 2.11.0