diff options
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index b3386842..a2735195 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -58,9 +58,6 @@ const char *email = "devel@monitoring-plugins.org"; | |||
58 | # define ERROR -1 | 58 | # define ERROR -1 |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | /* If nonzero, show inode information. */ | ||
62 | static int inode_format = 1; | ||
63 | |||
64 | /* If nonzero, show even filesystems with zero size or | 61 | /* If nonzero, show even filesystems with zero size or |
65 | uninteresting types. */ | 62 | uninteresting types. */ |
66 | static int show_all_fs = 1; | 63 | static int show_all_fs = 1; |
@@ -144,6 +141,7 @@ int erronly = FALSE; | |||
144 | int display_mntp = FALSE; | 141 | int display_mntp = FALSE; |
145 | int exact_match = FALSE; | 142 | int exact_match = FALSE; |
146 | int freespace_ignore_reserved = FALSE; | 143 | int freespace_ignore_reserved = FALSE; |
144 | int display_inodes_perfdata = FALSE; | ||
147 | char *warn_freespace_units = NULL; | 145 | char *warn_freespace_units = NULL; |
148 | char *crit_freespace_units = NULL; | 146 | char *crit_freespace_units = NULL; |
149 | char *warn_freespace_percent = NULL; | 147 | char *warn_freespace_percent = NULL; |
@@ -170,6 +168,7 @@ main (int argc, char **argv) | |||
170 | char *output; | 168 | char *output; |
171 | char *details; | 169 | char *details; |
172 | char *perf; | 170 | char *perf; |
171 | char *perf_ilabel; | ||
173 | char *preamble; | 172 | char *preamble; |
174 | char *flag_header; | 173 | char *flag_header; |
175 | double inode_space_pct; | 174 | double inode_space_pct; |
@@ -178,7 +177,7 @@ main (int argc, char **argv) | |||
178 | int temp_result; | 177 | int temp_result; |
179 | 178 | ||
180 | struct mount_entry *me; | 179 | struct mount_entry *me; |
181 | struct fs_usage fsp, tmpfsp; | 180 | struct fs_usage fsp; |
182 | struct parameter_list *temp_list, *path; | 181 | struct parameter_list *temp_list, *path; |
183 | 182 | ||
184 | #ifdef __CYGWIN__ | 183 | #ifdef __CYGWIN__ |
@@ -189,6 +188,7 @@ main (int argc, char **argv) | |||
189 | output = strdup (""); | 188 | output = strdup (""); |
190 | details = strdup (""); | 189 | details = strdup (""); |
191 | perf = strdup (""); | 190 | perf = strdup (""); |
191 | perf_ilabel = strdup (""); | ||
192 | stat_buf = malloc(sizeof *stat_buf); | 192 | stat_buf = malloc(sizeof *stat_buf); |
193 | 193 | ||
194 | setlocale (LC_ALL, ""); | 194 | setlocale (LC_ALL, ""); |
@@ -351,6 +351,29 @@ main (int argc, char **argv) | |||
351 | TRUE, 0, | 351 | TRUE, 0, |
352 | TRUE, path->dtotal_units)); | 352 | TRUE, path->dtotal_units)); |
353 | 353 | ||
354 | if (display_inodes_perfdata) { | ||
355 | /* *_high_tide must be reinitialized at each run */ | ||
356 | warning_high_tide = UINT_MAX; | ||
357 | critical_high_tide = UINT_MAX; | ||
358 | |||
359 | 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 )); | ||
361 | } | ||
362 | 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 )); | ||
364 | } | ||
365 | |||
366 | 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 */ | ||
368 | xasprintf (&perf, "%s %s", perf, | ||
369 | perfdata (perf_ilabel, | ||
370 | path->inodes_used, "", | ||
371 | (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide, | ||
372 | (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide, | ||
373 | TRUE, 0, | ||
374 | TRUE, path->inodes_total)); | ||
375 | } | ||
376 | |||
354 | if (disk_result==STATE_OK && erronly && !verbose) | 377 | if (disk_result==STATE_OK && erronly && !verbose) |
355 | continue; | 378 | continue; |
356 | 379 | ||
@@ -423,9 +446,7 @@ process_arguments (int argc, char **argv) | |||
423 | int c, err; | 446 | int c, err; |
424 | struct parameter_list *se; | 447 | struct parameter_list *se; |
425 | struct parameter_list *temp_list = NULL, *previous = NULL; | 448 | struct parameter_list *temp_list = NULL, *previous = NULL; |
426 | struct parameter_list *temp_path_select_list = NULL; | 449 | struct mount_entry *me; |
427 | struct mount_entry *me, *temp_me; | ||
428 | int result = OK; | ||
429 | regex_t re; | 450 | regex_t re; |
430 | int cflags = REG_NOSUB | REG_EXTENDED; | 451 | int cflags = REG_NOSUB | REG_EXTENDED; |
431 | int default_cflags = cflags; | 452 | int default_cflags = cflags; |
@@ -460,6 +481,7 @@ process_arguments (int argc, char **argv) | |||
460 | {"ignore-eregi-partition", required_argument, 0, 'I'}, | 481 | {"ignore-eregi-partition", required_argument, 0, 'I'}, |
461 | {"local", no_argument, 0, 'l'}, | 482 | {"local", no_argument, 0, 'l'}, |
462 | {"stat-remote-fs", no_argument, 0, 'L'}, | 483 | {"stat-remote-fs", no_argument, 0, 'L'}, |
484 | {"iperfdata", no_argument, 0, 'P'}, | ||
463 | {"mountpoint", no_argument, 0, 'M'}, | 485 | {"mountpoint", no_argument, 0, 'M'}, |
464 | {"errors-only", no_argument, 0, 'e'}, | 486 | {"errors-only", no_argument, 0, 'e'}, |
465 | {"exact-match", no_argument, 0, 'E'}, | 487 | {"exact-match", no_argument, 0, 'E'}, |
@@ -482,7 +504,7 @@ process_arguments (int argc, char **argv) | |||
482 | strcpy (argv[c], "-t"); | 504 | strcpy (argv[c], "-t"); |
483 | 505 | ||
484 | while (1) { | 506 | while (1) { |
485 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option); | 507 | c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option); |
486 | 508 | ||
487 | if (c == -1 || c == EOF) | 509 | if (c == -1 || c == EOF) |
488 | break; | 510 | break; |
@@ -587,9 +609,13 @@ process_arguments (int argc, char **argv) | |||
587 | break; | 609 | break; |
588 | case 'L': | 610 | case 'L': |
589 | stat_remote_fs = 1; | 611 | stat_remote_fs = 1; |
612 | /* fallthrough */ | ||
590 | case 'l': | 613 | case 'l': |
591 | show_local_fs = 1; | 614 | show_local_fs = 1; |
592 | break; | 615 | break; |
616 | case 'P': | ||
617 | display_inodes_perfdata = 1; | ||
618 | break; | ||
593 | case 'p': /* select path */ | 619 | case 'p': /* select path */ |
594 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || | 620 | if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || |
595 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || | 621 | crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || |
@@ -909,6 +935,8 @@ print_help (void) | |||
909 | printf (" %s\n", _("Display only devices/mountpoints with errors")); | 935 | printf (" %s\n", _("Display only devices/mountpoints with errors")); |
910 | printf (" %s\n", "-f, --freespace-ignore-reserved"); | 936 | printf (" %s\n", "-f, --freespace-ignore-reserved"); |
911 | printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata")); | 937 | printf (" %s\n", _("Don't account root-reserved blocks into freespace in perfdata")); |
938 | printf (" %s\n", "-P, --iperfdata"); | ||
939 | printf (" %s\n", _("Display inode usage in perfdata")); | ||
912 | printf (" %s\n", "-g, --group=NAME"); | 940 | printf (" %s\n", "-g, --group=NAME"); |
913 | printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); | 941 | printf (" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together")); |
914 | printf (" %s\n", "-k, --kilobytes"); | 942 | printf (" %s\n", "-k, --kilobytes"); |
@@ -1017,6 +1045,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1017 | p->dtotal_units += p_list->dtotal_units; | 1045 | p->dtotal_units += p_list->dtotal_units; |
1018 | p->inodes_total += p_list->inodes_total; | 1046 | p->inodes_total += p_list->inodes_total; |
1019 | p->inodes_free += p_list->inodes_free; | 1047 | p->inodes_free += p_list->inodes_free; |
1048 | p->inodes_free_to_root += p_list->inodes_free_to_root; | ||
1049 | p->inodes_used += p_list->inodes_used; | ||
1020 | } | 1050 | } |
1021 | first = 0; | 1051 | first = 0; |
1022 | } | 1052 | } |
@@ -1052,7 +1082,18 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) { | |||
1052 | p->dused_units = p->used*fsp->fsu_blocksize/mult; | 1082 | p->dused_units = p->used*fsp->fsu_blocksize/mult; |
1053 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; | 1083 | p->dfree_units = p->available*fsp->fsu_blocksize/mult; |
1054 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; | 1084 | p->dtotal_units = p->total*fsp->fsu_blocksize/mult; |
1055 | p->inodes_total = fsp->fsu_files; /* Total file nodes. */ | 1085 | /* Free file nodes. Not sure the workaround is required, but in case...*/ |
1056 | p->inodes_free = fsp->fsu_ffree; /* Free file nodes. */ | 1086 | p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail; |
1087 | p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */ | ||
1088 | p->inodes_used = fsp->fsu_files - fsp->fsu_ffree; | ||
1089 | if (freespace_ignore_reserved) { | ||
1090 | /* option activated : we substract the root-reserved inodes from the total */ | ||
1091 | /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */ | ||
1092 | /* for others, fsp->fsu_ffree == fsp->fsu_favail */ | ||
1093 | p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free; | ||
1094 | } else { | ||
1095 | /* default behaviour : take all the inodes into account */ | ||
1096 | p->inodes_total = fsp->fsu_files; | ||
1097 | } | ||
1057 | np_add_name(&seen, p->best_match->me_mountdir); | 1098 | np_add_name(&seen, p->best_match->me_mountdir); |
1058 | } | 1099 | } |