summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 204cf4f)
raw | patch | inline | side by side (parent: 204cf4f)
author | Tim Laszlo <Tim.Laszlo@magnetar.com> | |
Fri, 28 Feb 2014 18:43:36 +0000 (12:43 -0600) | ||
committer | Tim Laszlo <Tim.Laszlo@magnetar.com> | |
Fri, 28 Feb 2014 18:43:36 +0000 (12:43 -0600) |
AUTHORS | patch | blob | history | |
README | patch | blob | history | |
configure.ac | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/collectd.conf.in | patch | blob | history | |
src/drbd.c | [new file with mode: 0644] | patch | blob |
src/types.db | patch | blob | history |
index 31d132fbfa3c12cf27948ab5e1c9019ddab49adc..d8e32eeae2647893e4a7398762d692ca9fc388c9 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
- netapp plugin.
- python plugin.
+Tim Laszlo <tim.laszlo at gmail.com>
+ - drbd plugin
+
Thomas Meson <zllak at hycik.org>
- Graphite support for the AMQP plugin.
index fa88f387c7339ecb4790c0bbadb4b45353f0050f..0bef9f90c39593f147594af30e401bfa159b074d 100644 (file)
--- a/README
+++ b/README
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 f1c7b8aba1169f3a01f7bdf7993c52d192d4871f..e619ee51460a4f7e23b725c5ada849674b995416 100644 (file)
--- a/configure.ac
+++ b/configure.ac
plugin_curl_xml="no"
plugin_df="no"
plugin_disk="no"
+plugin_drbd="no"
plugin_entropy="no"
plugin_ethstat="no"
plugin_fscache="no"
plugin_cpu="yes"
plugin_cpufreq="yes"
plugin_disk="yes"
+ plugin_drbd="yes"
plugin_entropy="yes"
plugin_fscache="yes"
plugin_interface="yes"
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])
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 a9d858232a9ec547f42e52d335b1d3e5ff2da5eb..3ffccb43e7baba478904349042ecaf2d46851592 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
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 830add9929cf2f553edf4c49a5b15af1fb41560e..75c9299c13f44da1c2c98df881cb53f20857d9cc 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#@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
--- /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 <tim.laszlo at gmail.com>
+ **/
+
+/*
+ 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 97cc4cc08ad81a640be9b6550d0435deb447e9ba..2f399fc41b2cefc18fcc6210c1d04bc364efa7bb 100644 (file)
--- a/src/types.db
+++ b/src/types.db
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