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>
28 static void lvm_submit (char const *plugin_instance, char const *type_instance,
32 value_list_t vl = VALUE_LIST_INIT;
34 v.gauge = (gauge_t) ivalue;
39 sstrncpy(vl.host, hostname_g, sizeof (vl.host));
40 sstrncpy(vl.plugin, "lvm", sizeof (vl.plugin));
41 sstrncpy(vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
42 sstrncpy(vl.type, "df_complex", sizeof (vl.type));
43 sstrncpy(vl.type_instance, type_instance, sizeof (vl.type_instance));
45 plugin_dispatch_values (&vl);
48 static int vg_read(vg_t vg, char const *vg_name)
51 struct lvm_lv_list *lvl;
53 lvm_submit (vg_name, "free", lvm_vg_get_free_size(vg));
55 lvs = lvm_vg_list_lvs(vg);
56 dm_list_iterate_items(lvl, lvs) {
57 lvm_submit(vg_name, lvm_lv_get_name(lvl->lv), lvm_lv_get_size(lvl->lv));
63 static int lvm_read(void)
66 struct dm_list *vg_names;
67 struct lvm_str_list *name_list;
71 ERROR("lvm plugin: lvm_init failed.");
75 vg_names = lvm_list_vg_names(lvm);
77 ERROR("lvm plugin lvm_list_vg_name failed %s", lvm_errmsg(lvm));
82 dm_list_iterate_items(name_list, vg_names) {
85 vg = lvm_vg_open(lvm, name_list->str, "r", 0);
87 ERROR ("lvm plugin: lvm_vg_open (%s) failed: %s",
88 name_list->str, lvm_errmsg(lvm));
92 vg_read(vg, name_list->str);
100 void module_register(void)
102 plugin_register_read("lvm", lvm_read);
103 } /* void module_register */