summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c184
1 files changed, 101 insertions, 83 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index a273519..c526d05 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -1,29 +1,29 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_disk plugin 3* Monitoring check_disk plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 1999-2008 Monitoring Plugins Development Team 6* Copyright (c) 1999-2008 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains the check_disk plugin 10* This file contains the check_disk plugin
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* 26*
27*****************************************************************************/ 27*****************************************************************************/
28 28
29const char *progname = "check_disk"; 29const char *progname = "check_disk";
@@ -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
@@ -172,8 +172,6 @@ main (int argc, char **argv)
172 char *preamble; 172 char *preamble;
173 char *flag_header; 173 char *flag_header;
174 double inode_space_pct; 174 double inode_space_pct;
175 double warning_high_tide;
176 double critical_high_tide;
177 int temp_result; 175 int temp_result;
178 176
179 struct mount_entry *me; 177 struct mount_entry *me;
@@ -245,17 +243,17 @@ main (int argc, char **argv)
245 243
246#ifdef __CYGWIN__ 244#ifdef __CYGWIN__
247 if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11) 245 if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11)
248 continue; 246 continue;
249 snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10); 247 snprintf(mountdir, sizeof(mountdir), "%s:\\", me->me_mountdir + 10);
250 if (GetDriveType(mountdir) != DRIVE_FIXED) 248 if (GetDriveType(mountdir) != DRIVE_FIXED)
251 me->me_remote = 1; 249 me->me_remote = 1;
252#endif 250#endif
253 /* Filters */ 251 /* Filters */
254 252
255 /* Remove filesystems already seen */ 253 /* Remove filesystems already seen */
256 if (np_seen_name(seen, me->me_mountdir)) { 254 if (np_seen_name(seen, me->me_mountdir)) {
257 continue; 255 continue;
258 } 256 }
259 np_add_name(&seen, me->me_mountdir); 257 np_add_name(&seen, me->me_mountdir);
260 258
261 if (path->group == NULL) { 259 if (path->group == NULL) {
@@ -288,8 +286,17 @@ main (int argc, char **argv)
288 get_stats (path, &fsp); 286 get_stats (path, &fsp);
289 287
290 if (verbose >= 3) { 288 if (verbose >= 3) {
291 printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g 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",
292 me->me_mountdir, path->dused_pct, path->dfree_pct, path->dused_units, path->dfree_units, path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult); 290 me->me_mountdir,
291 path->dused_pct,
292 path->dfree_pct,
293 path->dused_units,
294 path->dfree_units,
295 path->dtotal_units,
296 path->dused_inodes_percent,
297 path->dfree_inodes_percent,
298 fsp.fsu_blocksize,
299 mult);
293 } 300 }
294 301
295 /* Threshold comparisons */ 302 /* Threshold comparisons */
@@ -326,77 +333,79 @@ main (int argc, char **argv)
326 */ 333 */
327 334
328 /* *_high_tide must be reinitialized at each run */ 335 /* *_high_tide must be reinitialized at each run */
329 warning_high_tide = UINT_MAX; 336 uint64_t warning_high_tide = UINT64_MAX;
330 critical_high_tide = UINT_MAX;
331 337
332 if (path->freespace_units->warning != NULL) { 338 if (path->freespace_units->warning != NULL) {
333 warning_high_tide = path->dtotal_units - path->freespace_units->warning->end; 339 warning_high_tide = (path->dtotal_units - path->freespace_units->warning->end) * mult;
334 } 340 }
335 if (path->freespace_percent->warning != NULL) { 341 if (path->freespace_percent->warning != NULL) {
336 warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freespace_percent->warning->end/100)*path->dtotal_units )); 342 warning_high_tide = min( warning_high_tide, (uint64_t)((1.0 - path->freespace_percent->warning->end/100) * (path->dtotal_units * mult)) );
337 } 343 }
344
345 uint64_t critical_high_tide = UINT64_MAX;
346
338 if (path->freespace_units->critical != NULL) { 347 if (path->freespace_units->critical != NULL) {
339 critical_high_tide = path->dtotal_units - path->freespace_units->critical->end; 348 critical_high_tide = (path->dtotal_units - path->freespace_units->critical->end) * mult;
340 } 349 }
341 if (path->freespace_percent->critical != NULL) { 350 if (path->freespace_percent->critical != NULL) {
342 critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*path->dtotal_units )); 351 critical_high_tide = min( critical_high_tide, (uint64_t)((1.0 - path->freespace_percent->critical->end/100) * (path->dtotal_units * mult)) );
343 } 352 }
344 353
345 /* Nb: *_high_tide are unset when == UINT_MAX */ 354 /* Nb: *_high_tide are unset when == UINT64_MAX */
346 xasprintf (&perf, "%s %s", perf, 355 xasprintf (&perf, "%s %s", perf,
347 perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 356 perfdata_uint64 (
348 path->dused_units, units, 357 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
349 (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, 358 path->dused_units * mult, "B",
350 (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, 359 (warning_high_tide == UINT64_MAX ? FALSE : TRUE), warning_high_tide,
351 TRUE, 0, 360 (critical_high_tide == UINT64_MAX ? FALSE : TRUE), critical_high_tide,
352 TRUE, path->dtotal_units)); 361 TRUE, 0,
362 TRUE, path->dtotal_units * mult));
353 363
354 if (display_inodes_perfdata) { 364 if (display_inodes_perfdata) {
355 /* *_high_tide must be reinitialized at each run */ 365 /* *_high_tide must be reinitialized at each run */
356 warning_high_tide = UINT_MAX; 366 warning_high_tide = UINT64_MAX;
357 critical_high_tide = UINT_MAX; 367 critical_high_tide = UINT64_MAX;
358 368
359 if (path->freeinodes_percent->warning != NULL) { 369 if (path->freeinodes_percent->warning != NULL) {
360 warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total )); 370 warning_high_tide = llabs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
361 } 371 }
362 if (path->freeinodes_percent->critical != NULL) { 372 if (path->freeinodes_percent->critical != NULL) {
363 critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total )); 373 critical_high_tide = llabs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
364 } 374 }
365 375
366 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);
367 /* Nb: *_high_tide are unset when == UINT_MAX */ 377 /* Nb: *_high_tide are unset when == UINT64_MAX */
368 xasprintf (&perf, "%s %s", perf, 378 xasprintf (&perf, "%s %s", perf,
369 perfdata (perf_ilabel, 379 perfdata_uint64 (perf_ilabel,
370 path->inodes_used, "", 380 path->inodes_used, "",
371 (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, 381 (warning_high_tide != UINT64_MAX ? TRUE : FALSE), warning_high_tide,
372 (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, 382 (critical_high_tide != UINT64_MAX ? TRUE : FALSE), critical_high_tide,
373 TRUE, 0, 383 TRUE, 0,
374 TRUE, path->inodes_total)); 384 TRUE, path->inodes_total));
375 } 385 }
376 386
377 if (disk_result==STATE_OK && erronly && !verbose) 387 if (disk_result==STATE_OK && erronly && !verbose)
378 continue; 388 continue;
379 389
380 if(disk_result && verbose >= 1) { 390 if(disk_result && verbose >= 1) {
381 xasprintf(&flag_header, " %s [", state_text (disk_result)); 391 xasprintf(&flag_header, " %s [", state_text (disk_result));
382 } else { 392 } else {
383 xasprintf(&flag_header, ""); 393 xasprintf(&flag_header, "");
384 } 394 }
385 xasprintf (&output, "%s%s %s %.0f %s (%.0f%%", 395 xasprintf (&output, "%s%s %s %llu%s (%.0f%%",
386 output, flag_header, 396 output, flag_header,
387 (!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,
388 path->dfree_units, 398 path->dfree_units,
389 units, 399 units,
390 path->dfree_pct); 400 path->dfree_pct);
391 if (path->dused_inodes_percent < 0) { 401 if (path->dused_inodes_percent < 0) {
392 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : "")); 402 xasprintf(&output, "%s inode=-)%s;", output, (disk_result ? "]" : ""));
393 } else { 403 } else {
394 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) ? "]" : ""));
395 } 405 }
396 free(flag_header); 406 free(flag_header);
397 /* TODO: Need to do a similar debug line 407 /* TODO: Need to do a similar debug line
398 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%%"),
399%.0f of %.0f %s (%.0f%% inode=%.0f%%) free on %s (type %s mounted on %s) warn:%lu crit:%lu warn%%:%.0f%% crit%%:%.0f%%"),
400 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct, 409 details, dfree_units, dtotal_units, units, dfree_pct, inode_space_pct,
401 me->me_devname, me->me_type, me->me_mountdir, 410 me->me_devname, me->me_type, me->me_mountdir,
402 (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);
@@ -557,14 +566,14 @@ process_arguments (int argc, char **argv)
557 } 566 }
558 break; 567 break;
559 568
560 case 'W': /* warning inode threshold */ 569 case 'W': /* warning inode threshold */
561 if (*optarg == '@') { 570 if (*optarg == '@') {
562 warn_freeinodes_percent = optarg; 571 warn_freeinodes_percent = optarg;
563 } else { 572 } else {
564 xasprintf(&warn_freeinodes_percent, "@%s", optarg); 573 xasprintf(&warn_freeinodes_percent, "@%s", optarg);
565 } 574 }
566 break; 575 break;
567 case 'K': /* critical inode threshold */ 576 case 'K': /* critical inode threshold */
568 if (*optarg == '@') { 577 if (*optarg == '@') {
569 crit_freeinodes_percent = optarg; 578 crit_freeinodes_percent = optarg;
570 } else { 579 } else {
@@ -574,21 +583,24 @@ process_arguments (int argc, char **argv)
574 case 'u': 583 case 'u':
575 if (units) 584 if (units)
576 free(units); 585 free(units);
577 if (! strcmp (optarg, "bytes")) { 586 if (! strcasecmp (optarg, "bytes")) {
578 mult = (uintmax_t)1; 587 mult = (uintmax_t)1;
579 units = strdup ("B"); 588 units = strdup ("B");
580 } else if (! strcmp (optarg, "kB")) { 589 } else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) {
581 mult = (uintmax_t)1024; 590 mult = (uintmax_t)1024;
582 units = strdup ("kB"); 591 units = strdup ("kiB");
583 } else if (! strcmp (optarg, "MB")) { 592 } else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) {
584 mult = (uintmax_t)1024 * 1024; 593 mult = (uintmax_t)1024 * 1024;
585 units = strdup ("MB"); 594 units = strdup ("MiB");
586 } else if (! strcmp (optarg, "GB")) { 595 } else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) {
587 mult = (uintmax_t)1024 * 1024 * 1024; 596 mult = (uintmax_t)1024 * 1024 * 1024;
588 units = strdup ("GB"); 597 units = strdup ("GiB");
589 } else if (! strcmp (optarg, "TB")) { 598 } else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) {
590 mult = (uintmax_t)1024 * 1024 * 1024 * 1024; 599 mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
591 units = strdup ("TB"); 600 units = strdup ("TiB");
601 } else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) {
602 mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024;
603 units = strdup ("PiB");
592 } else { 604 } else {
593 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg); 605 die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
594 } 606 }
@@ -599,13 +611,13 @@ process_arguments (int argc, char **argv)
599 mult = 1024; 611 mult = 1024;
600 if (units) 612 if (units)
601 free(units); 613 free(units);
602 units = strdup ("kB"); 614 units = strdup ("kiB");
603 break; 615 break;
604 case 'm': /* display mountpoint */ 616 case 'm': /* display mountpoint */
605 mult = 1024 * 1024; 617 mult = 1024 * 1024;
606 if (units) 618 if (units)
607 free(units); 619 free(units);
608 units = strdup ("MB"); 620 units = strdup ("MiB");
609 break; 621 break;
610 case 'L': 622 case 'L':
611 stat_remote_fs = 1; 623 stat_remote_fs = 1;
@@ -812,7 +824,7 @@ process_arguments (int argc, char **argv)
812 } 824 }
813 825
814 if (units == NULL) { 826 if (units == NULL) {
815 units = strdup ("MB"); 827 units = strdup ("MiB");
816 mult = (uintmax_t)1024 * 1024; 828 mult = (uintmax_t)1024 * 1024;
817 } 829 }
818 830
@@ -1026,20 +1038,20 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1026 if (p_list->group && ! (strcmp(p_list->group, p->group))) { 1038 if (p_list->group && ! (strcmp(p_list->group, p->group))) {
1027 stat_path(p_list); 1039 stat_path(p_list);
1028 get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp); 1040 get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp);
1029 get_path_stats(p_list, &tmpfsp); 1041 get_path_stats(p_list, &tmpfsp);
1030 if (verbose >= 3) 1042 if (verbose >= 3)
1031 printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n", 1043 printf("Group %s: adding %llu blocks sized %llu, (%s) used_units=%g free_units=%g total_units=%g fsu_blocksize=%llu mult=%llu\n",
1032 p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units, 1044 p_list->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p_list->best_match->me_mountdir, p_list->dused_units, p_list->dfree_units,
1033 p_list->dtotal_units, mult); 1045 p_list->dtotal_units, mult);
1034 1046
1035 /* prevent counting the first FS of a group twice since its parameter_list entry 1047 /* prevent counting the first FS of a group twice since its parameter_list entry
1036 * is used to carry the information of all file systems of the entire group */ 1048 * is used to carry the information of all file systems of the entire group */
1037 if (! first) { 1049 if (! first) {
1038 p->total += p_list->total; 1050 p->total += p_list->total;
1039 p->available += p_list->available; 1051 p->available += p_list->available;
1040 p->available_to_root += p_list->available_to_root; 1052 p->available_to_root += p_list->available_to_root;
1041 p->used += p_list->used; 1053 p->used += p_list->used;
1042 1054
1043 p->dused_units += p_list->dused_units; 1055 p->dused_units += p_list->dused_units;
1044 p->dfree_units += p_list->dfree_units; 1056 p->dfree_units += p_list->dfree_units;
1045 p->dtotal_units += p_list->dtotal_units; 1057 p->dtotal_units += p_list->dtotal_units;
@@ -1050,20 +1062,26 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1050 } 1062 }
1051 first = 0; 1063 first = 0;
1052 } 1064 }
1053 if (verbose >= 3) 1065 if (verbose >= 3)
1054 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",
1055 p->group, tmpfsp.fsu_bavail, tmpfsp.fsu_blocksize, p->best_match->me_mountdir, p->dused_units, 1067 p->group,
1056 p->dfree_units, p->dtotal_units, mult); 1068 tmpfsp.fsu_bavail,
1069 tmpfsp.fsu_blocksize,
1070 p->best_match->me_mountdir,
1071 p->dused_units,
1072 p->dfree_units,
1073 p->dtotal_units,
1074 mult);
1057 } 1075 }
1058 /* modify devname and mountdir for output */ 1076 /* modify devname and mountdir for output */
1059 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;
1060 } 1078 }
1061 /* finally calculate percentages for either plain FS or summed up group */ 1079 /* finally calculate percentages for either plain FS or summed up group */
1062 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 */
1063 p->dfree_pct = 100 - p->dused_pct; 1081 p->dfree_pct = 100 - p->dused_pct;
1064 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);
1065 p->dfree_inodes_percent = 100 - p->dused_inodes_percent; 1083 p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
1066 1084
1067} 1085}
1068 1086
1069void 1087void
@@ -1078,7 +1096,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
1078 /* default behaviour : take all the blocks into account */ 1096 /* default behaviour : take all the blocks into account */
1079 p->total = fsp->fsu_blocks; 1097 p->total = fsp->fsu_blocks;
1080 } 1098 }
1081 1099
1082 p->dused_units = p->used*fsp->fsu_blocksize/mult; 1100 p->dused_units = p->used*fsp->fsu_blocksize/mult;
1083 p->dfree_units = p->available*fsp->fsu_blocksize/mult; 1101 p->dfree_units = p->available*fsp->fsu_blocksize/mult;
1084 p->dtotal_units = p->total*fsp->fsu_blocksize/mult; 1102 p->dtotal_units = p->total*fsp->fsu_blocksize/mult;