@cryptotaxi247 / netdata-1 / commits / ec8b7ad7e

diskstats: Ensure collecting right space metrics

Check before writing space metrics to database that they where collected for the right disk.

Simon Nagl committed May 8, 2016 at 14:26 UTC ec8b7ad7e8473dfd7394c4eb0f059d39226162c8
1 file changed +30 -25
src/proc_diskstats.c
+30 -25
@@ -6,6 +6,7 @@
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 +#include <sys/stat.h>
10 #include <sys/statvfs.h>
11 #include <sys/types.h>
12 #include <unistd.h>
@@ -138,6 +139,7 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
139 static int enable_new_disks = -1;
140 static int do_io = -1, do_ops = -1, do_mops = -1, do_iotime = -1, do_qops = -1, do_util = -1, do_backlog = -1, do_space = -1;
141 static struct statvfs buff_statvfs;
142 + static struct stat buff_stat;
143
144 if(enable_new_disks == -1) enable_new_disks = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "enable new disks detected at runtime", CONFIG_ONDEMAND_ONDEMAND);
145
@@ -667,34 +669,37 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
669
670 // --------------------------------------------------------------------
671
670 - if(ddo_space) {
671 - if(!mount_point) {
672 - if(ddo_space != CONFIG_ONDEMAND_ONDEMAND) {
673 - error("Cannot find space usage for disk %s. It does not have a mount point.", family);
674 - }
672 + if(ddo_space && mount_point) {
673 + // collect space metrics using statvfs
674 + if (statvfs(mount_point, &buff_statvfs) < 0) {
675 + error("Failed checking disk space usage of %s", family);
676 } else {
676 - if (statvfs(family, &buff_statvfs) < 0) {
677 - error("Failed checking disk space usage of %s", family);
677 + // verify we collected the metrics for the right disk.
678 + // if not the mountpoint has changed.
679 + if(stat(mount_point, &buff_stat) == -1) {
680 } else {
679 - space_avail = buff_statvfs.f_bavail * buff_statvfs.f_bsize;
680 - space_avail_root = (buff_statvfs.f_bfree - buff_statvfs.f_bavail) * buff_statvfs.f_bsize;
681 - space_used = (buff_statvfs.f_blocks - buff_statvfs.f_bfree) * buff_statvfs.f_bsize;
682 -
683 - st = rrdset_find_bytype("disk_space", disk);
684 - if(!st) {
685 - st = rrdset_create("disk_space", disk, NULL, family, "disk.space", "Disk Space Usage", "GB", 2023, update_every, RRDSET_TYPE_STACKED);
686 - st->isdetail = 1;
687 -
688 - rrddim_add(st, "avail", NULL, 1, 1000*1000*1000, RRDDIM_ABSOLUTE);
689 - rrddim_add(st, "reserved_for_root", "reserved for root", 1, 1000*1000*1000, RRDDIM_ABSOLUTE);
690 - rrddim_add(st, "used" , NULL, 1, 1000*1000*1000, RRDDIM_ABSOLUTE);
691 - }
692 - else rrdset_next_usec(st, dt);
681 + if(major(buff_stat.st_dev) == major && minor(buff_stat.st_dev) == minor)
682 + {
683 + space_avail = buff_statvfs.f_bavail * buff_statvfs.f_bsize;
684 + space_avail_root = (buff_statvfs.f_bfree - buff_statvfs.f_bavail) * buff_statvfs.f_bsize;
685 + space_used = (buff_statvfs.f_blocks - buff_statvfs.f_bfree) * buff_statvfs.f_bsize;
686 +
687 + st = rrdset_find_bytype("disk_space", disk);
688 + if(!st) {
689 + st = rrdset_create("disk_space", disk, NULL, family, "disk.space", "Disk Space Usage", "GB", 2023, update_every, RRDSET_TYPE_STACKED);
690 + st->isdetail = 1;
691 +
692 + rrddim_add(st, "avail", NULL, 1, 1000*1000*1000, RRDDIM_ABSOLUTE);
693 + rrddim_add(st, "reserved_for_root", "reserved for root", 1, 1000*1000*1000, RRDDIM_ABSOLUTE);
694 + rrddim_add(st, "used" , NULL, 1, 1000*1000*1000, RRDDIM_ABSOLUTE);
695 + }
696 + else rrdset_next_usec(st, dt);
697
694 - rrddim_set(st, "avail", space_avail);
695 - rrddim_set(st, "reserved_for_root", space_avail_root);
696 - rrddim_set(st, "used", space_used);
697 - rrdset_done(st);
698 + rrddim_set(st, "avail", space_avail);
699 + rrddim_set(st, "reserved_for_root", space_avail_root);
700 + rrddim_set(st, "used", space_used);
701 + rrdset_done(st);
702 + }
703 }
704 }
705 }