summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8208520)
raw | patch | inline | side by side (parent: 8208520)
author | Michael Hanselmann <public@hansmi.ch> | |
Tue, 22 Feb 2011 23:18:12 +0000 (00:18 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 27 Feb 2012 07:26:58 +0000 (08:26 +0100) |
This is an initial implementation of a plugin to collect information
about Linux Software-RAID (md) devices. It reports the number of
component devices, number of devices in array, number of active,
working, failed and spare disks.
Change-Id: Id0ba8e678f33153112e9999c6341dd2ce71b10c0
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Signed-off-by: Florian Forster <octo@collectd.org>
about Linux Software-RAID (md) devices. It reports the number of
component devices, number of devices in array, number of active,
working, failed and spare disks.
Change-Id: Id0ba8e678f33153112e9999c6341dd2ce71b10c0
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Signed-off-by: Florian Forster <octo@collectd.org>
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/md.c | [new file with mode: 0644] | patch | blob |
src/types.db | patch | blob | history |
diff --git a/configure.in b/configure.in
index 9e1bf0941865b3536fd982a4b5789addfb5ef7f1..61e61feaeb2e28881a29a12c29efa078abae9328 100644 (file)
--- a/configure.in
+++ b/configure.in
# For hddtemp module
AC_CHECK_HEADERS(linux/major.h libgen.h)
+# For md module (Linux only)
+if test "x$ac_system" = "xLinux"
+then
+ AC_CHECK_HEADERS(linux/raid/md_u.h,
+ [have_linux_raid_md_u_h="yes"],
+ [have_linux_raid_md_u_h="no"],
+[
+#include <sys/ioctl.h>
+#include <linux/major.h>
+#include <linux/types.h>
+])
+else
+ have_linux_raid_md_u_h="no"
+fi
+
# For the battery plugin
AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [],
[
AC_PLUGIN([match_timediff], [yes], [The timediff match])
AC_PLUGIN([match_value], [yes], [The value match])
AC_PLUGIN([mbmon], [yes], [Query mbmond])
+AC_PLUGIN([md], [$have_linux_raid_md_u_h], [md (Linux software RAID) devices])
AC_PLUGIN([memcachec], [$with_libmemcached], [memcachec statistics])
AC_PLUGIN([memcached], [yes], [memcached statistics])
AC_PLUGIN([memory], [$plugin_memory], [Memory usage])
match_timediff . . . $enable_match_timediff
match_value . . . . . $enable_match_value
mbmon . . . . . . . . $enable_mbmon
+ md . . . . . . . . . $enable_md
memcachec . . . . . . $enable_memcachec
memcached . . . . . . $enable_memcached
memory . . . . . . . $enable_memory
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f2acc0f099ff10918bb833a0206125b963d2d3e..0869a0867b977b1fc297ec400f887976a8167e07 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
collectd_DEPENDENCIES += mbmon.la
endif
+if BUILD_PLUGIN_MD
+pkglib_LTLIBRARIES += md.la
+md_la_SOURCES = md.c
+md_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" md.la
+collectd_DEPENDENCIES += md.la
+endif
+
if BUILD_PLUGIN_MEMCACHEC
pkglib_LTLIBRARIES += memcachec.la
memcachec_la_SOURCES = memcachec.c
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 983f5f1676d56bb9bee043a4c4dddfdb92d5cffa..a6aa89c389e276888899dd4272c4c8c4ff136858 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#@BUILD_PLUGIN_LPAR_TRUE@LoadPlugin lpar
#@BUILD_PLUGIN_MADWIFI_TRUE@LoadPlugin madwifi
#@BUILD_PLUGIN_MBMON_TRUE@LoadPlugin mbmon
+#@BUILD_PLUGIN_MD_TRUE@LoadPlugin md
#@BUILD_PLUGIN_MEMCACHEC_TRUE@LoadPlugin memcachec
#@BUILD_PLUGIN_MEMCACHED_TRUE@LoadPlugin memcached
@BUILD_PLUGIN_MEMORY_TRUE@@BUILD_PLUGIN_MEMORY_TRUE@LoadPlugin memory
# Port "411"
#</Plugin>
+#<Plugin md>
+# Device "/dev/md0"
+# IgnoreSelected false
+#</Plugin>
+
#<Plugin memcachec>
# <Page "plugin_instance">
# Server "localhost"
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 2be3c939fa410900bb27b30ec7b6a0c4ad12c22a..a90826a8de514b478c3509782920295000ff94d6 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
=back
+=head2 Plugin C<md>
+
+The C<md plugin> collects information from Linux Software-RAID devices (md).
+
+All reported values are of the type C<md_disks>. Reported type instances are
+"number" (number of component devices), "raid" (number of devices in the
+array), "active", "working", "failed" (number of failed disks) and "spare"
+(number of spare disks).
+
+=over 4
+
+=item B<Device> I<Device>
+
+Select md devices based on device name. The I<device name> is the basename of
+the device, i.e. the name of the block device without the leading C</dev/>.
+See B<IgnoreSelected> for more details.
+
+=item B<IgnoreSelected> I<true>|I<false>
+
+Invert device selection: If set to true, all md devices B<except> those listed
+using B<Device> are collected. If false (the default), only those listed are
+collected. If no configuration is given, the B<md> plugin will collect data
+from all md devices.
+
+=back
+
=head2 Plugin C<memcachec>
The C<memcachec plugin> connects to a memcached server, queries one or more
diff --git a/src/md.c b/src/md.c
--- /dev/null
+++ b/src/md.c
@@ -0,0 +1,204 @@
+/**
+ * collectd - src/md.c
+ * Copyright (C) 2010,2011 Michael Hanselmann
+ *
+ * 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
+ *
+ * Author:
+ * Michael Hanselmann
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_ignorelist.h"
+
+#include <sys/ioctl.h>
+
+#include <linux/major.h>
+#include <linux/raid/md_u.h>
+
+#define PROC_DISKSTATS "/proc/diskstats"
+#define DEV_DIR "/dev"
+
+static const char *config_keys[] =
+{
+ "Device",
+ "IgnoreSelected"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static ignorelist_t *ignorelist = NULL;
+
+static int md_config (const char *key, const char *value)
+{
+ if (ignorelist == NULL)
+ ignorelist = ignorelist_create (/* invert = */ 1);
+ if (ignorelist == NULL)
+ return (1);
+
+ if (strcasecmp (key, "Device") == 0)
+ {
+ ignorelist_add (ignorelist, value);
+ }
+ else if (strcasecmp (key, "IgnoreSelected") == 0)
+ {
+ ignorelist_set_invert (ignorelist, IS_TRUE (value) ? 0 : 1);
+ }
+ else
+ {
+ return (-1);
+ }
+
+ return (0);
+}
+
+static void md_submit (const int minor, const char *type_instance,
+ gauge_t value)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].gauge = value;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "md", sizeof (vl.plugin));
+ ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
+ "%i", minor);
+ sstrncpy (vl.type, "md_disks", sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance,
+ sizeof (vl.type_instance));
+
+ plugin_dispatch_values (&vl);
+} /* void md_submit */
+
+static void md_process (const int minor, const char *path)
+{
+ char errbuf[1024];
+ int fd;
+ struct stat st;
+ mdu_array_info_t array;
+
+ fd = open (path, O_RDONLY);
+ if (fd < 0)
+ {
+ WARNING ("md: open(%s): %s", path,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return;
+ }
+
+ if (fstat (fd, &st) < 0)
+ {
+ WARNING ("md: Unable to fstat file descriptor for %s: %s", path,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ close (fd);
+ return;
+ }
+
+ if (! S_ISBLK (st.st_mode))
+ {
+ WARNING ("md: %s is no block device", path);
+ close (fd);
+ return;
+ }
+
+ if (st.st_rdev != makedev (MD_MAJOR, minor))
+ {
+ WARNING ("md: Major/minor of %s are %i:%i, should be %i:%i",
+ path, (int)major(st.st_rdev), (int)minor(st.st_rdev),
+ (int)MD_MAJOR, minor);
+ close (fd);
+ return;
+ }
+
+ /* Retrieve md information */
+ if (ioctl (fd, GET_ARRAY_INFO, &array) < 0) {
+ WARNING ("md: Unable to retrieve array info from %s: %s", path,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ close (fd);
+ return;
+ }
+
+ close (fd);
+
+ md_submit (minor, "number", (gauge_t) array.nr_disks);
+ md_submit (minor, "raid", (gauge_t) array.raid_disks);
+ md_submit (minor, "active", (gauge_t) array.active_disks);
+ md_submit (minor, "working", (gauge_t) array.working_disks);
+ md_submit (minor, "failed", (gauge_t) array.failed_disks);
+ md_submit (minor, "spare", (gauge_t) array.spare_disks);
+
+ return;
+} /* void md_process */
+
+static int md_read (void)
+{
+ FILE *fh;
+ char buffer[1024];
+
+ fh = fopen (PROC_DISKSTATS, "r");
+ if (fh == NULL) {
+ char errbuf[1024];
+ WARNING ("md: Unable to open %s: %s",
+ PROC_DISKSTATS ,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+
+ /* Iterate md devices */
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {
+ char path[PATH_MAX];
+ char *fields[4];
+ char *name;
+ int major, minor;
+
+ /* Extract interesting fields */
+ if (strsplit (buffer, fields, STATIC_ARRAY_SIZE(fields)) < 3)
+ continue;
+
+ major = atoi (fields[0]);
+
+ if (major != MD_MAJOR)
+ continue;
+
+ minor = atoi (fields[1]);
+ name = fields[2];
+
+ if (ignorelist_match (ignorelist, name))
+ continue;
+
+ /* FIXME: Don't hardcode path. Walk /dev collecting major,
+ * minor and name, then use lookup table to find device.
+ * Alternatively create a temporary device file with correct
+ * major/minor, but that again can be tricky if the filesystem
+ * with the device file is mounted using the "nodev" option.
+ */
+ ssnprintf (path, sizeof (path), "%s/%s", DEV_DIR, name);
+
+ md_process (minor, path);
+ }
+
+ fclose (fh);
+
+ return (0);
+} /* int md_read */
+
+void module_register (void)
+{
+ plugin_register_config ("md", md_config, config_keys, config_keys_num);
+ plugin_register_read ("md", md_read);
+} /* void module_register */
diff --git a/src/types.db b/src/types.db
index e6345ab6df64b878040a5057ed1b5a41b6fe4985..8557fe6bec4d57ad833a30d184cb32c4ebad467f 100644 (file)
--- a/src/types.db
+++ b/src/types.db
latency value:GAUGE:0:65535
links value:GAUGE:0:U
load shortterm:GAUGE:0:100, midterm:GAUGE:0:100, longterm:GAUGE:0:100
+md_disks value:GAUGE:0:U
memcached_command value:DERIVE:0:U
memcached_connections value:GAUGE:0:U
memcached_items value:GAUGE:0:U