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.c52
1 files changed, 49 insertions, 3 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index e73a008..844e625 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -141,6 +141,7 @@ int erronly = FALSE;
141int display_mntp = FALSE; 141int display_mntp = FALSE;
142int exact_match = FALSE; 142int exact_match = FALSE;
143int freespace_ignore_reserved = FALSE; 143int freespace_ignore_reserved = FALSE;
144int display_inodes_perfdata = FALSE;
144char *warn_freespace_units = NULL; 145char *warn_freespace_units = NULL;
145char *crit_freespace_units = NULL; 146char *crit_freespace_units = NULL;
146char *warn_freespace_percent = NULL; 147char *warn_freespace_percent = NULL;
@@ -167,6 +168,7 @@ main (int argc, char **argv)
167 char *output; 168 char *output;
168 char *details; 169 char *details;
169 char *perf; 170 char *perf;
171 char *perf_ilabel;
170 char *preamble; 172 char *preamble;
171 char *flag_header; 173 char *flag_header;
172 double inode_space_pct; 174 double inode_space_pct;
@@ -186,6 +188,7 @@ main (int argc, char **argv)
186 output = strdup (""); 188 output = strdup ("");
187 details = strdup (""); 189 details = strdup ("");
188 perf = strdup (""); 190 perf = strdup ("");
191 perf_ilabel = strdup ("");
189 stat_buf = malloc(sizeof *stat_buf); 192 stat_buf = malloc(sizeof *stat_buf);
190 193
191 setlocale (LC_ALL, ""); 194 setlocale (LC_ALL, "");
@@ -348,6 +351,29 @@ main (int argc, char **argv)
348 TRUE, 0, 351 TRUE, 0,
349 TRUE, path->dtotal_units)); 352 TRUE, path->dtotal_units));
350 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
351 if (disk_result==STATE_OK && erronly && !verbose) 377 if (disk_result==STATE_OK && erronly && !verbose)
352 continue; 378 continue;
353 379
@@ -455,6 +481,7 @@ process_arguments (int argc, char **argv)
455 {"ignore-eregi-partition", required_argument, 0, 'I'}, 481 {"ignore-eregi-partition", required_argument, 0, 'I'},
456 {"local", no_argument, 0, 'l'}, 482 {"local", no_argument, 0, 'l'},
457 {"stat-remote-fs", no_argument, 0, 'L'}, 483 {"stat-remote-fs", no_argument, 0, 'L'},
484 {"iperfdata", no_argument, 0, 'P'},
458 {"mountpoint", no_argument, 0, 'M'}, 485 {"mountpoint", no_argument, 0, 'M'},
459 {"errors-only", no_argument, 0, 'e'}, 486 {"errors-only", no_argument, 0, 'e'},
460 {"exact-match", no_argument, 0, 'E'}, 487 {"exact-match", no_argument, 0, 'E'},
@@ -477,7 +504,7 @@ process_arguments (int argc, char **argv)
477 strcpy (argv[c], "-t"); 504 strcpy (argv[c], "-t");
478 505
479 while (1) { 506 while (1) {
480 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);
481 508
482 if (c == -1 || c == EOF) 509 if (c == -1 || c == EOF)
483 break; 510 break;
@@ -582,9 +609,13 @@ process_arguments (int argc, char **argv)
582 break; 609 break;
583 case 'L': 610 case 'L':
584 stat_remote_fs = 1; 611 stat_remote_fs = 1;
612 /* fallthrough */
585 case 'l': 613 case 'l':
586 show_local_fs = 1; 614 show_local_fs = 1;
587 break; 615 break;
616 case 'P':
617 display_inodes_perfdata = 1;
618 break;
588 case 'p': /* select path */ 619 case 'p': /* select path */
589 if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || 620 if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
590 crit_freespace_percent || warn_usedspace_units || crit_usedspace_units || 621 crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
@@ -904,6 +935,8 @@ print_help (void)
904 printf (" %s\n", _("Display only devices/mountpoints with errors")); 935 printf (" %s\n", _("Display only devices/mountpoints with errors"));
905 printf (" %s\n", "-f, --freespace-ignore-reserved"); 936 printf (" %s\n", "-f, --freespace-ignore-reserved");
906 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"));
907 printf (" %s\n", "-g, --group=NAME"); 940 printf (" %s\n", "-g, --group=NAME");
908 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"));
909 printf (" %s\n", "-k, --kilobytes"); 942 printf (" %s\n", "-k, --kilobytes");
@@ -1012,6 +1045,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1012 p->dtotal_units += p_list->dtotal_units; 1045 p->dtotal_units += p_list->dtotal_units;
1013 p->inodes_total += p_list->inodes_total; 1046 p->inodes_total += p_list->inodes_total;
1014 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;
1015 } 1050 }
1016 first = 0; 1051 first = 0;
1017 } 1052 }
@@ -1050,7 +1085,18 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
1050 p->dused_units = p->used*fsp->fsu_blocksize/mult; 1085 p->dused_units = p->used*fsp->fsu_blocksize/mult;
1051 p->dfree_units = p->available*fsp->fsu_blocksize/mult; 1086 p->dfree_units = p->available*fsp->fsu_blocksize/mult;
1052 p->dtotal_units = p->total*fsp->fsu_blocksize/mult; 1087 p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
1053 p->inodes_total = fsp->fsu_files; /* Total file nodes. */ 1088 /* Free file nodes. Not sure the workaround is required, but in case...*/
1054 p->inodes_free = fsp->fsu_ffree; /* Free file nodes. */ 1089 p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail;
1090 p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */
1091 p->inodes_used = fsp->fsu_files - fsp->fsu_ffree;
1092 if (freespace_ignore_reserved) {
1093 /* option activated : we substract the root-reserved inodes from the total */
1094 /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */
1095 /* for others, fsp->fsu_ffree == fsp->fsu_favail */
1096 p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free;
1097 } else {
1098 /* default behaviour : take all the inodes into account */
1099 p->inodes_total = fsp->fsu_files;
1100 }
1055 np_add_name(&seen, p->best_match->me_mountdir); 1101 np_add_name(&seen, p->best_match->me_mountdir);
1056} 1102}