From ec8e5a75c21aefe8103fff904272029a09b4b9c5 Mon Sep 17 00:00:00 2001 From: Chad Malfait Date: Wed, 10 Apr 2013 19:57:07 -0600 Subject: [PATCH] Added logical volume size metrics --- .project | 11 ++++++++++ src/volume.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 .project diff --git a/.project b/.project new file mode 100644 index 00000000..4780775c --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + collectd + + + + + + + + diff --git a/src/volume.c b/src/volume.c index aa250258..a6fe0c3d 100644 --- a/src/volume.c +++ b/src/volume.c @@ -25,8 +25,30 @@ #include "common.h" #include "plugin.h" -static void volume_submit(const char *vol_name, const char *type, const char *type_instance, gauge_t value) +static void vg_submit(const char *vg_name, gauge_t used, gauge_t free, gauge_t size) { + value_t values[3]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = used; + values[1].gauge = free; + values[2].gauge = size; + + vl.values = values; + vl.values_len = STATIC_ARRAY_SIZE (values); + + sstrncpy(vl.host, hostname_g, sizeof (vl.host)); + sstrncpy(vl.plugin, "vg", sizeof (vl.plugin)); + sstrncpy(vl.plugin_instance, vg_name, sizeof (vl.plugin_instance)); + sstrncpy(vl.type, "vg", sizeof (vl.type)); + sstrncpy(vl.type_instance, vg_name, sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} + +static void lv_submit(const char *vg_name, const char *lv_name, gauge_t value) +{ + value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -34,14 +56,34 @@ static void volume_submit(const char *vol_name, const char *type, const char *ty vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); + sstrncpy(vl.host, hostname_g, sizeof (vl.host)); - sstrncpy(vl.type, type, sizeof (vl.type)); - sstrncpy(vl.type_instance, type_instance, sizeof (vl.type_instance)); + sstrncpy(vl.plugin, "vg", sizeof (vl.plugin)); + sstrncpy(vl.plugin_instance, vg_name, sizeof (vl.plugin_instance)); + sstrncpy(vl.type, "lv", sizeof (vl.type)); + sstrncpy(vl.type_instance, lv_name, sizeof (vl.type_instance)); - plugin_dispatch_values (&vl); + plugin_dispatch_values (&vl); +} + +static int lv_read(vg_t vg, const char *vg_name, unsigned long vg_free, unsigned long vg_size) +{ + struct dm_list *lvs; + struct lvm_lv_list *lvl; + unsigned long vg_used = 0; + + vg_used = vg_size - vg_free; + lvs = lvm_vg_list_lvs(vg); + + vg_submit(vg_name, vg_used, vg_free, vg_size); + + dm_list_iterate_items(lvl, lvs) { + lv_submit(vg_name, lvm_lv_get_name(lvl->lv), lvm_lv_get_size(lvl->lv)); + } + return (0); } -static int volume_read(void) +static int vg_read(void) { lvm_t lvm; vg_t vg; @@ -51,28 +93,29 @@ static int volume_read(void) lvm = lvm_init(NULL); if (!lvm) { ERROR("volume plugin: lvm_init failed: %s", lvm_errmsg(lvm)); - return (lvm_errno(lvm)); + lvm_quit(lvm); + exit(-1); } vg_names = lvm_list_vg_names(lvm); if (!vg_names) { ERROR("volume plugin lvm_list_vg_name failed %s", lvm_errmsg(lvm)); - return (lvm_errno(lvm)); + lvm_quit(lvm); + exit(-1); } 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)); + lv_read(vg, name_list->str, lvm_vg_get_free_size(vg), lvm_vg_get_size(vg)); lvm_vg_close(vg); } lvm_quit(lvm); return (0); -} +} /*vg_read */ void module_register(void) { - plugin_register_read("volume", volume_read); + plugin_register_read("volume", vg_read); } /* void module_register */ -- 2.11.0