From c7d196de1e4a8329b60b32004f93743bcf9b143d Mon Sep 17 00:00:00 2001 From: Chad Malfait Date: Sat, 6 Apr 2013 19:32:27 -0600 Subject: [PATCH] added the use of df_complex and changed fprintf to ERROR for error messages. Also changed variable names to follow recommended standard from the website. --- src/volume.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/volume.c b/src/volume.c index ab39dc90..3cb6d28c 100644 --- a/src/volume.c +++ b/src/volume.c @@ -19,24 +19,24 @@ * Chad Malfait **/ +#include + #include "collectd.h" #include "common.h" #include "plugin.h" -#include -static void volume_submit(const char *vol_name, gauge_t size, gauge_t free) +static void volume_submit(const char *vol_name, const char *type, const char type_instance, gauge_t value) { - value_t values[2]; + value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = size; - values[1].gauge = free; + values[0].gauge = value; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy(vl.host, hostname_g, sizeof (vl.host)); - sstrncpy(vl.plugin, "volume", sizeof (vl.plugin)); - sstrncpy(vl.type, vol_name, sizeof (vl.type)); + sstrncpy(vl.type, type, sizeof (vl.type)); + sstrncpy(vl.type_instance, type_instacne, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } @@ -45,22 +45,27 @@ static int volume_read(void) { lvm_t lvm; vg_t vg; - struct dm_list *vgnames; - struct lvm_str_list *strl; + int status = 0; + struct dm_list *vg_names; + struct lvm_str_list *name_list; lvm = lvm_init(NULL); if (!lvm) { - fprintf(stderr, "lvm_init() failed\n"); + status = lvm_errno(lvm); + ERROR("volume plugin: lvm_init failed: %s", lvm_errmsg(lvm)); } - vgnames = lvm_list_vg_names(lvm); - if (!vgnames) { - fprintf(stderr, "lvm_list_vg_names() failed\n"); + vg_names = lvm_list_vg_names(lvm); + if (!vg_names) { + status = lvm_errno(lvm); + ERROR("volume plugin lvm_list_vg_name failed %s", lvm_errmsg(lvm)); } - dm_list_iterate_items(strl, vgnames) { - vg = lvm_vg_open(lvm, strl->str, "r", 0); - volume_submit(strl->str, lvm_vg_get_size(vg), lvm_vg_get_free_size(vg)); + dm_list_iterate_items(name_list, vg_names) { + vg = lvm_vg_open(lvm, name_list->str, "r", 0); + volume_submit(name_list->str, "df_complex", "size", lvm_vg_get_size(vg)); + volume_submit(name_list->str, "df_complex", "free", lvm_vg_get_free_size(vg)); + lvm_vg_close(vg); } -- 2.11.0