2 * collectd - src/volume.c
3 * Copyright (C) 2013 Chad Malfait
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Chad Malfait <malfaitc at yahoo.com>
27 static void volume_submit(const char *vol_name, gauge_t size, gauge_t free)
30 value_list_t vl = VALUE_LIST_INIT;
32 values[0].gauge = size;
33 values[1].gauge = free;
36 vl.values_len = STATIC_ARRAY_SIZE (values);
37 sstrncpy(vl.host, hostname_g, sizeof (vl.host));
38 sstrncpy(vl.plugin, "volume", sizeof (vl.plugin));
39 sstrncpy(vl.type, vol_name, sizeof (vl.type));
41 plugin_dispatch_values (&vl);
44 static int volume_read(void)
48 struct dm_list *vgnames;
49 struct lvm_str_list *strl;
53 fprintf(stderr, "lvm_init() failed\n");
56 vgnames = lvm_list_vg_names(lvm);
58 fprintf(stderr, "lvm_list_vg_names() failed\n");
61 dm_list_iterate_items(strl, vgnames) {
62 vg = lvm_vg_open(lvm, strl->str, "r", 0);
63 volume_submit(strl->str, lvm_vg_get_size(vg), lvm_vg_get_free_size(vg));
71 void module_register(void)
73 plugin_register_read("volume", volume_read);
74 } /* void module_register */