* Chad Malfait <malfaitc at yahoo.com>
**/
+#include <lvm2app.h>
+
#include "collectd.h"
#include "common.h"
#include "plugin.h"
-#include <lvm2app.h>
-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);
}
{
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);
}