check if mount point is a directory for enabling disk space monitoring for mount points; fixes #2407
Costa Tsaousis (ktsaou) committed
Jul 7, 2017 at 23:22 UTC
47d1fd2b4aa5eb1f29e227f3cf08d4fa626649a9
1 file changed
+33
-6
src/plugin_proc_diskspace.c
+33
-6
@@ -125,6 +125,33 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
125
def_inodes = CONFIG_BOOLEAN_NO;
126
}
127
128
+ // check if the mount point is a directory #2407
129
+ {
130
+ struct stat bs;
131
+ if(stat(mi->mount_point, &bs) == -1) {
132
+ error("DISKSPACE: Cannot stat() mount point '%s' (disk '%s', filesystem '%s', root '%s')."
133
+ , mi->mount_point
134
+ , disk
135
+ , mi->filesystem?mi->filesystem:""
136
+ , mi->root?mi->root:""
137
+ );
138
+ def_space = CONFIG_BOOLEAN_NO;
139
+ def_inodes = CONFIG_BOOLEAN_NO;
140
+ }
141
+ else {
142
+ if((bs.st_mode & S_IFMT) != S_IFDIR) {
143
+ error("DISKSPACE: Mount point '%s' (disk '%s', filesystem '%s', root '%s') is not a directory."
144
+ , mi->mount_point
145
+ , disk
146
+ , mi->filesystem?mi->filesystem:""
147
+ , mi->root?mi->root:""
148
+ );
149
+ def_space = CONFIG_BOOLEAN_NO;
150
+ def_inodes = CONFIG_BOOLEAN_NO;
151
+ }
152
+ }
153
+ }
154
+
155
do_space = config_get_boolean_ondemand(var_name, "space usage", def_space);
156
do_inodes = config_get_boolean_ondemand(var_name, "inodes usage", def_inodes);
157
@@ -161,7 +188,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
188
struct statvfs buff_statvfs;
189
if (statvfs(mi->mount_point, &buff_statvfs) < 0) {
190
if(!m->shown_error) {
164
- error("Failed statvfs() for '%s' (disk '%s', filesystem '%s', root '%s')"
191
+ error("DISKSPACE: failed to statvfs() mount point '%s' (disk '%s', filesystem '%s', root '%s')"
192
, mi->mount_point
193
, disk
194
, mi->filesystem?mi->filesystem:""
@@ -188,7 +215,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
215
216
#ifdef NETDATA_INTERNAL_CHECKS
217
if(unlikely(btotal != bavail + breserved_root + bused))
191
- error("Disk block statistics for '%s' (disk '%s') do not sum up: total = %llu, available = %llu, reserved = %llu, used = %llu", mi->mount_point, disk, (unsigned long long)btotal, (unsigned long long)bavail, (unsigned long long)breserved_root, (unsigned long long)bused);
218
+ error("DISKSPACE: disk block statistics for '%s' (disk '%s') do not sum up: total = %llu, available = %llu, reserved = %llu, used = %llu", mi->mount_point, disk, (unsigned long long)btotal, (unsigned long long)bavail, (unsigned long long)breserved_root, (unsigned long long)bused);
219
#endif
220
221
// --------------------------------------------------------------------------
@@ -201,7 +228,7 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
228
229
#ifdef NETDATA_INTERNAL_CHECKS
230
if(unlikely(btotal != bavail + breserved_root + bused))
204
- error("Disk inode statistics for '%s' (disk '%s') do not sum up: total = %llu, available = %llu, reserved = %llu, used = %llu", mi->mount_point, disk, (unsigned long long)ftotal, (unsigned long long)favail, (unsigned long long)freserved_root, (unsigned long long)fused);
231
+ error("DISKSPACE: disk inode statistics for '%s' (disk '%s') do not sum up: total = %llu, available = %llu, reserved = %llu, used = %llu", mi->mount_point, disk, (unsigned long long)ftotal, (unsigned long long)favail, (unsigned long long)freserved_root, (unsigned long long)fused);
232
#endif
233
234
// --------------------------------------------------------------------------
@@ -294,10 +321,10 @@ void *proc_diskspace_main(void *ptr) {
321
info("DISKSPACE thread created with task id %d", gettid());
322
323
if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
297
- error("Cannot set pthread cancel type to DEFERRED.");
324
+ error("DISKSPACE: Cannot set pthread cancel type to DEFERRED.");
325
326
if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
300
- error("Cannot set pthread cancel state to ENABLE.");
327
+ error("DISKSPACE: Cannot set pthread cancel state to ENABLE.");
328
329
int vdo_cpu_netdata = config_get_boolean("plugin:proc", "netdata server resources", 1);
330
@@ -334,7 +361,7 @@ void *proc_diskspace_main(void *ptr) {
361
struct mountinfo *mi;
362
for(mi = disk_mountinfo_root; mi; mi = mi->next) {
363
337
- if(unlikely(mi->flags & (MOUNTINFO_IS_DUMMY | MOUNTINFO_IS_BIND | MOUNTINFO_IS_SAME_DEV | MOUNTINFO_NO_STAT | MOUNTINFO_NO_SIZE)))
364
+ if(unlikely(mi->flags & (MOUNTINFO_IS_DUMMY | MOUNTINFO_IS_BIND)))
365
continue;
366
367
do_disk_space_stats(mi, update_every);