From: Tim Laszlo Date: Fri, 28 Feb 2014 18:43:36 +0000 (-0600) Subject: Collect drbd statistics on linux X-Git-Tag: collectd-5.5.0~233^2~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=df570a3614ad8fdcaa8dc1ef3f7e71128d71bffe;p=collectd.git Collect drbd statistics on linux --- diff --git a/AUTHORS b/AUTHORS index 31d132fb..d8e32eea 100644 --- a/AUTHORS +++ b/AUTHORS @@ -231,6 +231,9 @@ Sven Trenkel - netapp plugin. - python plugin. +Tim Laszlo + - drbd plugin + Thomas Meson - Graphite support for the AMQP plugin. diff --git a/README b/README index fa88f387..0bef9f90 100644 --- a/README +++ b/README @@ -82,6 +82,9 @@ Features DNS traffic: Query types, response codes, opcodes and traffic/octets transfered. + - drbd + Collect individual drbd resource statistics. + - email Email statistics: Count, traffic, spam scores and checks. See collectd-email(5). diff --git a/configure.ac b/configure.ac index f1c7b8ab..e619ee51 100644 --- a/configure.ac +++ b/configure.ac @@ -4797,6 +4797,7 @@ plugin_curl_json="no" plugin_curl_xml="no" plugin_df="no" plugin_disk="no" +plugin_drbd="no" plugin_entropy="no" plugin_ethstat="no" plugin_fscache="no" @@ -4836,6 +4837,7 @@ then plugin_cpu="yes" plugin_cpufreq="yes" plugin_disk="yes" + plugin_drbd="yes" plugin_entropy="yes" plugin_fscache="yes" plugin_interface="yes" @@ -5128,6 +5130,7 @@ AC_PLUGIN([cgroups], [$plugin_cgroups], [CGroups CPU usage accounting]) AC_PLUGIN([dbi], [$with_libdbi], [General database statistics]) AC_PLUGIN([df], [$plugin_df], [Filesystem usage statistics]) AC_PLUGIN([disk], [$plugin_disk], [Disk usage statistics]) +AC_PLUGIN([drbd], [$plugin_drbd], [DRBD statistics]) AC_PLUGIN([dns], [$with_libpcap], [DNS traffic analysis]) AC_PLUGIN([email], [yes], [EMail statistics]) AC_PLUGIN([entropy], [$plugin_entropy], [Entropy statistics]) @@ -5474,6 +5477,7 @@ Configuration: df . . . . . . . . . $enable_df disk . . . . . . . . $enable_disk dns . . . . . . . . . $enable_dns + drbd . . . . . . . . $enable_drbd email . . . . . . . . $enable_email entropy . . . . . . . $enable_entropy ethstat . . . . . . . $enable_ethstat diff --git a/src/Makefile.am b/src/Makefile.am index a9d85823..3ffccb43 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -401,6 +401,15 @@ collectd_LDADD += "-dlopen" dns.la collectd_DEPENDENCIES += dns.la endif +if BUILD_PLUGIN_DRBD +pkglib_LTLIBRARIES += drbd.la +drbd_la_SOURCES = drbd.c +drbd_la_LDFLAGS = -module -avoid-version +drbd_la_LIBADD = -lpthread +collectd_LDADD += "-dlopen" drbd.la +collectd_DEPENDENCIES += drbd.la +endif + if BUILD_PLUGIN_EMAIL pkglib_LTLIBRARIES += email.la email_la_SOURCES = email.c diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 830add99..75c9299c 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -96,6 +96,7 @@ #@BUILD_PLUGIN_DF_TRUE@LoadPlugin df #@BUILD_PLUGIN_DISK_TRUE@LoadPlugin disk #@BUILD_PLUGIN_DNS_TRUE@LoadPlugin dns +#@BUILD_PLUGIN_DRBD_TRUE@LoadPlugin drbd #@BUILD_PLUGIN_EMAIL_TRUE@LoadPlugin email #@BUILD_PLUGIN_ENTROPY_TRUE@LoadPlugin entropy #@BUILD_PLUGIN_ETHSTAT_TRUE@LoadPlugin ethstat diff --git a/src/drbd.c b/src/drbd.c new file mode 100644 index 00000000..800bf62d --- /dev/null +++ b/src/drbd.c @@ -0,0 +1,163 @@ +/** + * collectd - src/drbd.c + * Copyright (C) 2014 Tim Laszlo + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Tim Laszlo + **/ + +/* + See: http://www.drbd.org/users-guide/ch-admin.html#s-performance-indicators + + version: 8.3.11 (api:88/proto:86-96) + srcversion: 71955441799F513ACA6DA60 + 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate B r----- + ns:64363752 nr:0 dw:357799284 dr:846902273 al:34987022 bm:18062 lo:0 \ + pe:0 ua:0 ap:0 ep:1 wo:f oos:0 + */ + +#include "collectd.h" +#include "common.h" +#include "plugin.h" + +static const char *drbd_stats = "/proc/drbd"; +static const char *drbd_names[] = +{ + "network_send", /* ns (network send) */ + "network_recv", /* nr (network receive) */ + "disk_write", /* dw (disk write) */ + "disk_read", /* dr (disk read) */ + "activity_log", /* al (activity log) */ + "bitmap", /* bm (bit map) */ + "local_count", /* lo (local count) */ + "pending", /* pe (pending) */ + "unacknowledged", /* ua (unacknowledged) */ + "app pending", /* ap (application pending) */ + "epochs", /* ep (epochs) */ + NULL, /* wo (write order) */ + "oos" /* oos (out of sync) */ +}; +static size_t drbd_names_num = STATIC_ARRAY_SIZE (drbd_names); + +static int drbd_init (void) +{ + return (0); +} + + +static int drbd_submit_fields (int resource, + char **fields, size_t fields_num) +{ + char plugin_instance[DATA_MAX_NAME_LEN]; + value_t values[fields_num]; + value_list_t vl = VALUE_LIST_INIT; + size_t i; + + if (resource < 0) + { + WARNING ("drbd plugin: Unable to parse resource"); + return (EINVAL); + } + + if (fields_num != drbd_names_num) + { + WARNING ("drbd plugin: Wrong number of fields for " + "r%i statistics. Expected %zu, got %zu.", + resource, drbd_names_num, fields_num); + return (EINVAL); + } + + ssnprintf (plugin_instance, sizeof (plugin_instance), "r%i", + resource); + + for (i = 0; i < drbd_names_num; i++) + { + char *data; + /* skip non numeric wo */ + if (strncmp(fields[i], "wo", 2) == 0) + continue; + data = strchr(fields[i], ':'); + if (data == NULL) + return (EINVAL); + (void) parse_value (++data, &values[i], DS_TYPE_DERIVE); + } + + vl.values_len = 1; + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "drbd", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, + sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "drbd_resource", sizeof (vl.type)); + + for (i = 0; i < fields_num; i++) + { + if (drbd_names[i] == NULL) + continue; + vl.values = values + i; + sstrncpy (vl.type_instance, drbd_names[i], + sizeof (vl.type_instance)); + plugin_dispatch_values (&vl); + } + + return (0); +} /* drbd_submit_fields */ + +static int drbd_read (void) +{ + FILE *fh; + char buffer[256]; + + int resource = -1; + char *fields[16]; + int fields_num = 0; + + fh = fopen (drbd_stats, "r"); + if (fh == NULL) + { + WARNING ("Unable to open%s", drbd_stats); + return (EINVAL); + } + + while (fgets (buffer, sizeof (buffer), fh) != NULL) + { + fields_num = strsplit (buffer, + fields, STATIC_ARRAY_SIZE (fields)); + + /* ignore headers */ + if (fields_num < 4) + continue; + + if (isdigit(fields[0][0])) + { + /* parse the resource line */ + resource = atoi(fields[0]); + } + else + { + /* handle stats data */ + drbd_submit_fields(resource, fields, fields_num); + } + } /* while (fgets) */ + + fclose (fh); + return (0); +} /* void drbd_read */ + +void module_register (void) +{ + plugin_register_init ("drbd", drbd_init); + plugin_register_read ("drbd", drbd_read); +} /* void module_register */ diff --git a/src/types.db b/src/types.db index 97cc4cc0..2f399fc4 100644 --- a/src/types.db +++ b/src/types.db @@ -53,6 +53,7 @@ dns_response value:DERIVE:0:U dns_transfer value:DERIVE:0:U dns_update value:DERIVE:0:U dns_zops value:DERIVE:0:U +drbd_resource value:DERIVE:0:U duration seconds:GAUGE:0:U email_check value:GAUGE:0:U email_count value:GAUGE:0:U