diff options
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 109 |
1 files changed, 54 insertions, 55 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index cc6dbb7..c526d05 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
46 | #include <stdarg.h> | 46 | #include <stdarg.h> |
47 | #include "fsusage.h" | 47 | #include "fsusage.h" |
48 | #include "mountlist.h" | 48 | #include "mountlist.h" |
49 | #include "intprops.h" /* necessary for TYPE_MAXIMUM */ | 49 | #include "intprops.h" /* necessary for TYPE_MAXIMUM */ |
50 | #if HAVE_LIMITS_H | 50 | #if HAVE_LIMITS_H |
51 | # include <limits.h> | 51 | # include <limits.h> |
52 | #endif | 52 | #endif |
@@ -243,10 +243,10 @@ main (int argc, char **argv) | |||
243 | 243 | ||
244 | #ifdef __CYGWIN__ | 244 | #ifdef __CYGWIN__ |
245 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) | 245 | if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) |
246 | continue; | 246 | continue; |
247 | snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); | 247 | snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); |
248 | if (GetDriveType(mountdir) != DRIVE_FIXED) | 248 | if (GetDriveType(mountdir) != DRIVE_FIXED) |
249 | me->me_remote = 1; | 249 | me->me_remote = 1; |
250 | #endif | 250 | #endif |
251 | /* Filters */ | 251 | /* Filters */ |
252 | 252 | ||
@@ -287,16 +287,16 @@ main (int argc, char **argv) | |||
287 | 287 | ||
288 | if (verbose >= 3) { | 288 | if (verbose >= 3) { |
289 | printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", | 289 | printf ("For %s, used_pct=%g free_pct=%g used_units=%llu free_units=%llu total_units=%llu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", |
290 | me->me_mountdir, | 290 | me->me_mountdir, |
291 | path->dused_pct, | 291 | path->dused_pct, |
292 | path->dfree_pct, | 292 | path->dfree_pct, |
293 | path->dused_units, | 293 | path->dused_units, |
294 | path->dfree_units, | 294 | path->dfree_units, |
295 | path->dtotal_units, | 295 | path->dtotal_units, |
296 | path->dused_inodes_percent, | 296 | path->dused_inodes_percent, |
297 | path->dfree_inodes_percent, | 297 | path->dfree_inodes_percent, |
298 | fsp.fsu_blocksize, | 298 | fsp.fsu_blocksize, |
299 | mult); | 299 | mult); |
300 | } | 300 | } |
301 | 301 | ||
302 | /* Threshold comparisons */ | 302 | /* Threshold comparisons */ |
@@ -333,7 +333,7 @@ main (int argc, char **argv) | |||
333 | */ | 333 | */ |
334 | 334 | ||
335 | /* *_high_tide must be reinitialized at each run */ | 335 | /* *_high_tide must be reinitialized at each run */ |
336 | uint64_t warning_high_tide = UINT64_MAX; | 336 | uint64_t warning_high_tide = UINT64_MAX; |
337 | 337 | ||
338 | if (path->freespace_units->warning != NULL) { | 338 | if (path->freespace_units->warning != NULL) { |
339 | warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult; | 339 | warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult; |
@@ -342,7 +342,7 @@ main (int argc, char **argv) | |||
342 | warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) ); | 342 | warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) ); |
343 | } | 343 | } |
344 | 344 | ||
345 | uint64_t critical_high_tide = UINT64_MAX; | 345 | uint64_t critical_high_tide = UINT64_MAX; |
346 | 346 | ||
347 | if (path->freespace_units->critical != NULL) { | 347 | if (path->freespace_units->critical != NULL) { |
348 | critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult; | 348 | critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult; |
@@ -353,13 +353,13 @@ main (int argc, char **argv) | |||
353 | 353 | ||
354 | /* Nb: *_high_tide are unset when == UINT64_MAX */ | 354 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
355 | xasprintf (&perf, "%s %s", perf, | 355 | xasprintf (&perf, "%s %s", perf, |
356 | perfdata_uint64 ( | 356 | perfdata_uint64 ( |
357 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 357 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
358 | path->dused_units * mult, "B", | 358 | path->dused_units * mult, "B", |
359 | (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, | 359 | (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide, |
360 | (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, | 360 | (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide, |
361 | TRUE, 0, | 361 | TRUE, 0, |
362 | TRUE, path->dtotal_units * mult)); | 362 | TRUE, path->dtotal_units * mult)); |
363 | 363 | ||
364 | if (display_inodes_perfdata) { | 364 | if (display_inodes_perfdata) { |
365 | /* *_high_tide must be reinitialized at each run */ | 365 | /* *_high_tide must be reinitialized at each run */ |
@@ -376,37 +376,36 @@ main (int argc, char **argv) | |||
376 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); | 376 | xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir); |
377 | /* Nb: *_high_tide are unset when == UINT64_MAX */ | 377 | /* Nb: *_high_tide are unset when == UINT64_MAX */ |
378 | xasprintf (&perf, "%s %s", perf, | 378 | xasprintf (&perf, "%s %s", perf, |
379 | perfdata_uint64 (perf_ilabel, | 379 | perfdata_uint64 (perf_ilabel, |
380 | path->inodes_used, "", | 380 | path->inodes_used, "", |
381 | (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, | 381 | (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide, |
382 | (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, | 382 | (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide, |
383 | TRUE, 0, | 383 | TRUE, 0, |
384 | TRUE, path->inodes_total)); | 384 | TRUE, path->inodes_total)); |
385 | } | 385 | } |
386 | 386 | ||
387 | if (disk_result==STATE_OK && erronly && !verbose) | 387 | if (disk_result==STATE_OK && erronly && !verbose) |
388 | continue; | 388 | continue; |
389 | 389 | ||
390 | if(disk_result && verbose >= 1) { | 390 | if(disk_result && verbose >= 1) { |
391 | xasprintf(&flag_header, " %s [", state_text (disk_result)); | 391 | xasprintf(&flag_header, " %s [", state_text (disk_result)); |
392 | } else { | 392 | } else { |
393 | xasprintf(&flag_header, ""); | 393 | xasprintf(&flag_header, ""); |
394 | } | 394 | } |
395 | xasprintf (&output, "%s%s %s %llu%s (%.0f%%", | 395 | xasprintf (&output, "%s%s %s %llu%s (%.0f%%", |
396 | output, flag_header, | 396 | output, flag_header, |
397 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | 397 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, |
398 | path->dfree_units, | 398 | path->dfree_units, |
399 | units, | 399 | units, |
400 | path->dfree_pct); | 400 | path->dfree_pct); |
401 | if (path->dused_inodes_percent < 0) { | 401 | if (path->dused_inodes_percent < 0) { |
402 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); | 402 | xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); |
403 | } else { | 403 | } else { |
404 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); | 404 | xasprintf(&output, "%s inode=%.0f%%)%s;", output, path->dfree_inodes_percent, ((disk_result && verbose >= 1) ? "]" : "")); |
405 | } | 405 | } |
406 | free(flag_header); | 406 | free(flag_header); |
407 | /* TODO: Need to do a similar debug line | 407 | /* TODO: Need to do a similar debug line |
408 | xasprintf (&details, _("%s\n\ | 408 | xasprintf (&details, _("%s\n\%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), |
409 | %.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"), | ||
410 | details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, | 409 | details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, |
411 | me->me_devname, me->me_type, me->me_mountdir, | 410 | me->me_devname, me->me_type, me->me_mountdir, |
412 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); | 411 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); |
@@ -567,14 +566,14 @@ process_arguments (int argc, char **argv) | |||
567 | } | 566 | } |
568 | break; | 567 | break; |
569 | 568 | ||
570 | case 'W': /* warning inode threshold */ | 569 | case 'W': /* warning inode threshold */ |
571 | if (*optarg == '@') { | 570 | if (*optarg == '@') { |
572 | warn_freeinodes_percent = optarg; | 571 | warn_freeinodes_percent = optarg; |
573 | } else { | 572 | } else { |
574 | xasprintf(&warn_freeinodes_percent, "@%s", optarg); | 573 | xasprintf(&warn_freeinodes_percent, "@%s", optarg); |
575 | } | 574 | } |
576 | break; | 575 | break; |
577 | case 'K': /* critical inode threshold */ | 576 | case 'K': /* critical inode threshold */ |
578 | if (*optarg == '@') { | 577 | if (*optarg == '@') { |
579 | crit_freeinodes_percent = optarg; | 578 | crit_freeinodes_percent = optarg; |
580 | } else { | 579 | } else { |
@@ -1066,19 +1065,19 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1066 | if (verbose >= 3) | 1065 | if (verbose >= 3) |
1067 | printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", | 1066 | printf("Group %s now has: used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", |
1068 | p->group, | 1067 | p->group, |
1069 | tmpfsp.fsu_bavail, | 1068 | tmpfsp.fsu_bavail, |
1070 | tmpfsp.fsu_blocksize, | 1069 | tmpfsp.fsu_blocksize, |
1071 | p->best_match->me_mountdir, | 1070 | p->best_match->me_mountdir, |
1072 | p->dused_units, | 1071 | p->dused_units, |
1073 | p->dfree_units, | 1072 | p->dfree_units, |
1074 | p->dtotal_units, | 1073 | p->dtotal_units, |
1075 | mult); | 1074 | mult); |
1076 | } | 1075 | } |
1077 | /* modify devname and mountdir for output */ | 1076 | /* modify devname and mountdir for output */ |
1078 | p->best_match->me_mountdir = p->best_match->me_devname = p->group; | 1077 | p->best_match->me_mountdir = p->best_match->me_devname = p->group; |
1079 | } | 1078 | } |
1080 | /* finally calculate percentages for either plain FS or summed up group */ | 1079 | /* finally calculate percentages for either plain FS or summed up group */ |
1081 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ | 1080 | p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ |
1082 | p->dfree_pct = 100 - p->dused_pct; | 1081 | p->dfree_pct = 100 - p->dused_pct; |
1083 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); | 1082 | p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); |
1084 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; | 1083 | p->dfree_inodes_percent = 100 - p->dused_inodes_percent; |