@cryptotaxi247 / netdata-1 / commits / 57e49f1eb

prevent error flood when statvfs() fails

Costa Tsaousis (ktsaou) committed Feb 24, 2017 at 23:24 UTC 57e49f1eb38670625f5ee34baefad3e0b3bf0d92
1 file changed +15 -8
src/plugin_proc_diskspace.c
+15 -8
@@ -27,6 +27,7 @@ static inline void mountinfo_reload(int force) {
27 struct mount_point_metadata {
28 int do_space;
29 int do_inodes;
30 + int shown_error;
31
32 size_t collected; // the number of times this has been collected
33
@@ -95,6 +96,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
96 struct mount_point_metadata mp = {
97 .do_space = do_space,
98 .do_inodes = do_inodes,
99 + .shown_error = 0,
100
101 .collected = 0,
102
@@ -111,12 +113,8 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
113
114 m = dictionary_set(mount_points, mi->mount_point, &mp, sizeof(struct mount_point_metadata));
115 }
114 - else {
115 - do_space = m->do_space;
116 - do_inodes = m->do_inodes;
117 - }
116
119 - if(unlikely(do_space == CONFIG_BOOLEAN_NO && do_inodes == CONFIG_BOOLEAN_NO))
117 + if(unlikely(m->do_space == CONFIG_BOOLEAN_NO && m->do_inodes == CONFIG_BOOLEAN_NO))
118 return;
119
120 if(unlikely(mi->flags & MOUNTINFO_READONLY && !m->collected))
@@ -124,9 +122,18 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
122
123 struct statvfs buff_statvfs;
124 if (statvfs(mi->mount_point, &buff_statvfs) < 0) {
127 - error("Failed statvfs() for '%s' (disk '%s')", mi->mount_point, disk);
125 + if(!m->shown_error) {
126 + error("Failed statvfs() for '%s' (disk '%s', filesystem '%s', root '%s')"
127 + , mi->mount_point
128 + , disk
129 + , mi->filesystem?mi->filesystem:""
130 + , mi->root?mi->root:""
131 + );
132 + m->shown_error = 1;
133 + }
134 return;
135 }
136 + m->shown_error = 0;
137
138 // logic found at get_fs_usage() in coreutils
139 unsigned long bsize = (buff_statvfs.f_frsize) ? buff_statvfs.f_frsize : buff_statvfs.f_bsize;
@@ -163,7 +170,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
170
171 int rendered = 0;
172
166 - if(do_space == CONFIG_BOOLEAN_YES || (do_space == CONFIG_BOOLEAN_AUTO && (bavail || breserved_root || bused))) {
173 + if(m->do_space == CONFIG_BOOLEAN_YES || (m->do_space == CONFIG_BOOLEAN_AUTO && (bavail || breserved_root || bused))) {
174 if(unlikely(!m->st_space)) {
175 m->do_space = CONFIG_BOOLEAN_YES;
176 m->st_space = rrdset_find_bytype_localhost("disk_space", disk);
@@ -201,7 +208,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
208
209 // --------------------------------------------------------------------------
210
204 - if(do_inodes == CONFIG_BOOLEAN_YES || (do_inodes == CONFIG_BOOLEAN_AUTO && (favail || freserved_root || fused))) {
211 + if(m->do_inodes == CONFIG_BOOLEAN_YES || (m->do_inodes == CONFIG_BOOLEAN_AUTO && (favail || freserved_root || fused))) {
212 if(unlikely(!m->st_inodes)) {
213 m->do_inodes = CONFIG_BOOLEAN_YES;
214 m->st_inodes = rrdset_find_bytype_localhost("disk_inodes", disk);