summaryrefslogtreecommitdiffstats
path: root/plugins/check_disk.c
diff options
context:
space:
mode:
authorchl <dev+github@bugness.org>2012-10-12 12:43:04 (GMT)
committerchl <dev+github@bugness.org>2012-10-12 13:55:38 (GMT)
commita6ff5d44895deb07c7978218eec6f7e1cbdfa94a (patch)
treee3f5909b729eab921b0ade3ff4022f0fef480ae4 /plugins/check_disk.c
parent831bb312a9c8a76f1e24d144952ed7c757a2d09c (diff)
downloadmonitoring-plugins-a6ff5d44895deb07c7978218eec6f7e1cbdfa94a.tar.gz
check_disk: option to ignore reserved spacerefs/pull/22/head
This commit add a runtime option to ignore the root-reserved space when calculating perfdata. Before / after: ./check_disk -w 2% -c 1% /home ./check_disk -w 2% -c 1% -f /home DISK CRITICAL - free space: /home 272 MB (1% inode=83%);| /home=17551MB;18401;18589;0;18777 DISK CRITICAL - free space: /home 272 MB (1% inode=83%);| /home=17551MB;17466;17644;0;17823 Well, it doesn't really give me more space :) but the perfdata are a little bit more coherent. Note that there are still a rounding issue on the percent calculation (cf calculate_percent() comments, taken from coreutils 'df' command). 272/17823 -> 1.526% Since the warning/critical/min/max data are usually not saved in RRD DB, you can activate the option without seeing landslides in the graphs.
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r--plugins/check_disk.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 6ba7bdf..4d6156f 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -135,6 +135,7 @@ int verbose = 0;
135int erronly = FALSE; 135int erronly = FALSE;
136int display_mntp = FALSE; 136int display_mntp = FALSE;
137int exact_match = FALSE; 137int exact_match = FALSE;
138int freespace_ignore_reserved = FALSE;
138char *warn_freespace_units = NULL; 139char *warn_freespace_units = NULL;
139char *crit_freespace_units = NULL; 140char *crit_freespace_units = NULL;
140char *warn_freespace_percent = NULL; 141char *warn_freespace_percent = NULL;
@@ -424,6 +425,7 @@ process_arguments (int argc, char **argv)
424 {"eregi-partition", required_argument, 0, 'R'}, 425 {"eregi-partition", required_argument, 0, 'R'},
425 {"ereg-path", required_argument, 0, 'r'}, 426 {"ereg-path", required_argument, 0, 'r'},
426 {"ereg-partition", required_argument, 0, 'r'}, 427 {"ereg-partition", required_argument, 0, 'r'},
428 {"freespace-ignore-reserved", no_argument, 0, 'f'},
427 {"ignore-ereg-path", required_argument, 0, 'i'}, 429 {"ignore-ereg-path", required_argument, 0, 'i'},
428 {"ignore-ereg-partition", required_argument, 0, 'i'}, 430 {"ignore-ereg-partition", required_argument, 0, 'i'},
429 {"ignore-eregi-path", required_argument, 0, 'I'}, 431 {"ignore-eregi-path", required_argument, 0, 'I'},
@@ -452,7 +454,7 @@ process_arguments (int argc, char **argv)
452 strcpy (argv[c], "-t"); 454 strcpy (argv[c], "-t");
453 455
454 while (1) { 456 while (1) {
455 c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklLg:R:r:i:I:MEA", longopts, &option); 457 c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:mklLg:R:r:i:I:MEA", longopts, &option);
456 458
457 if (c == -1 || c == EOF) 459 if (c == -1 || c == EOF)
458 break; 460 break;
@@ -606,6 +608,9 @@ process_arguments (int argc, char **argv)
606 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n")); 608 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n"));
607 exact_match = TRUE; 609 exact_match = TRUE;
608 break; 610 break;
611 case 'f':
612 freespace_ignore_reserved = TRUE;
613 break;
609 case 'g': 614 case 'g':
610 if (path_selected) 615 if (path_selected)
611 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n")); 616 die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n"));
@@ -871,6 +876,8 @@ print_help (void)
871 printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths")); 876 printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths"));
872 printf (" %s\n", "-e, --errors-only"); 877 printf (" %s\n", "-e, --errors-only");
873 printf (" %s\n", _("Display only devices/mountpoints with errors")); 878 printf (" %s\n", _("Display only devices/mountpoints with errors"));
879 printf (" %s\n", "-f, --freespace-ignore-reserved");
880 printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata"));
874 printf (" %s\n", "-g, --group=NAME"); 881 printf (" %s\n", "-g, --group=NAME");
875 printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); 882 printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together"));
876 printf (" %s\n", "-k, --kilobytes"); 883 printf (" %s\n", "-k, --kilobytes");
@@ -921,7 +928,7 @@ print_usage (void)
921{ 928{
922 printf ("%s\n", _("Usage:")); 929 printf ("%s\n", _("Usage:"));
923 printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname); 930 printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname);
924 printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n"); 931 printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
925 printf ("[-t timeout] [-u unit] [-v] [-X type]\n"); 932 printf ("[-t timeout] [-u unit] [-v] [-X type]\n");
926} 933}
927 934
@@ -994,13 +1001,19 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
994 1001
995void 1002void
996get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { 1003get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
997 p->total = fsp->fsu_blocks;
998 /* 2007-12-08 - Workaround for Gnulib reporting insanely high available 1004 /* 2007-12-08 - Workaround for Gnulib reporting insanely high available
999 * space on BSD (the actual value should be negative but fsp->fsu_bavail 1005 * space on BSD (the actual value should be negative but fsp->fsu_bavail
1000 * is unsigned) */ 1006 * is unsigned) */
1001 p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail; 1007 p->available = fsp->fsu_bavail > fsp->fsu_bfree ? 0 : fsp->fsu_bavail;
1002 p->available_to_root = fsp->fsu_bfree; 1008 p->available_to_root = fsp->fsu_bfree;
1003 p->used = p->total - p->available_to_root; 1009 p->used = fsp->fsu_blocks - fsp->fsu_bfree;
1010 if (freespace_ignore_reserved) {
1011 /* option activated : we substract the root-reserved space from the total */
1012 p->total = fsp->fsu_blocks - p->available_to_root + p->available;
1013 } else {
1014 /* default behaviour : take all the blocks into account */
1015 p->total = fsp->fsu_blocks;
1016 }
1004 1017
1005 p->dused_units = p->used*fsp->fsu_blocksize/mult; 1018 p->dused_units = p->used*fsp->fsu_blocksize/mult;
1006 p->dfree_units = p->available*fsp->fsu_blocksize/mult; 1019 p->dfree_units = p->available*fsp->fsu_blocksize/mult;