From: Radoslaw Jablonski Date: Thu, 28 Feb 2019 14:14:01 +0000 (+0000) Subject: virt: Fetch block info stats from libvirt only if needed X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ce2eb567629eb21d650d5c27fefe607837c061fd;p=collectd.git virt: Fetch block info stats from libvirt only if needed Domain block info statistics will be retrieved from libvirt only if one of extra stats is enabled: - ex_stats_disk_allocation - ex_stats_disk_capacity - ex_stats_disk_physical Change-Id: I0367c6ec7aafbf9558aaa100a12d40605ab9ba72 Signed-off-by: Radoslaw Jablonski --- diff --git a/src/virt.c b/src/virt.c index a6f050d4..93f9cebf 100644 --- a/src/virt.c +++ b/src/virt.c @@ -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; + } } }