X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmd.c;h=793b172281c3eb0c22e8f9be8ee221a7f3c93d77;hb=7f8a8111b26ffaed85a4a48ba874614df3a07f1b;hp=fdac4e3d7478a75a82d7cc1ae6743a2eab6889e1;hpb=9ce2a30d4ef0e9763a245d16da98afc626c10846;p=collectd.git diff --git a/src/md.c b/src/md.c index fdac4e3d..793b1722 100644 --- a/src/md.c +++ b/src/md.c @@ -20,6 +20,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_ignorelist.h" @@ -29,6 +30,10 @@ #include #include +#ifdef HAVE_SYS_SYSMACROS_H +#include +#endif + #define PROC_DISKSTATS "/proc/diskstats" #define DEV_DIR "/dev" @@ -67,14 +72,10 @@ static int md_config (const char *key, const char *value) 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 = &(value_t) { .gauge = value }; 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); @@ -91,6 +92,7 @@ static void md_process (const int minor, const char *path) int fd; struct stat st; mdu_array_info_t array; + gauge_t disks_missing; fd = open (path, O_RDONLY); if (fd < 0) @@ -134,14 +136,27 @@ static void md_process (const int minor, const char *path) close (fd); - md_submit (minor, "number", (gauge_t) array.nr_disks); - md_submit (minor, "raid", (gauge_t) array.raid_disks); + /* + * The mdu_array_info_t structure contains numbers of disks in the array. + * However, disks are accounted for more than once: + * + * active: Number of active (in sync) disks. + * spare: Number of stand-by disks. + * working: Number of working disks. (active + sync) + * failed: Number of failed disks. + * nr: Number of physically present disks. (working + failed) + * raid: Number of disks in the RAID. This may be larger than "nr" if + * disks are missing and smaller than "nr" when spare disks are + * around. + */ 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; + disks_missing = 0.0; + if (array.raid_disks > array.nr_disks) + disks_missing = (gauge_t) (array.raid_disks - array.nr_disks); + md_submit (minor, "missing", disks_missing); } /* void md_process */ static int md_read (void)