summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorVincent Danjean <vdanjean@debian.org>2018-12-08 20:51:05 (GMT)
committerVincent Danjean <Vincent.Danjean@ens-lyon.org>2018-12-08 21:44:42 (GMT)
commit270e7cba3830328424e3f2b6b9a6989b1ea5f89b (patch)
tree99c01ee12cbad2ec381551156190a5e0135bbe44 /plugins
parentac6f101f057caa3083c092537e6dff97328cfd44 (diff)
downloadmonitoring-plugins-270e7cba3830328424e3f2b6b9a6989b1ea5f89b.tar.gz
[check_disk] add support to display inodes usage in perfdatarefs/pull/1567/head
This is not enabled by default It can be enabled with the -P (--iperfdata) option
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_disk.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index e73a008..1c43e85 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 ||
@@ -1012,6 +1043,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1012 p->dtotal_units += p_list->dtotal_units; 1043 p->dtotal_units += p_list->dtotal_units;
1013 p->inodes_total += p_list->inodes_total; 1044 p->inodes_total += p_list->inodes_total;
1014 p->inodes_free += p_list->inodes_free; 1045 p->inodes_free += p_list->inodes_free;
1046 p->inodes_free_to_root += p_list->inodes_free_to_root;
1047 p->inodes_used += p_list->inodes_used;
1015 } 1048 }
1016 first = 0; 1049 first = 0;
1017 } 1050 }
@@ -1050,7 +1083,18 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
1050 p->dused_units = p->used*fsp->fsu_blocksize/mult; 1083 p->dused_units = p->used*fsp->fsu_blocksize/mult;
1051 p->dfree_units = p->available*fsp->fsu_blocksize/mult; 1084 p->dfree_units = p->available*fsp->fsu_blocksize/mult;
1052 p->dtotal_units = p->total*fsp->fsu_blocksize/mult; 1085 p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
1053 p->inodes_total = fsp->fsu_files; /* Total file nodes. */ 1086 /* Free file nodes. Not sure the workaround is required, but in case...*/
1054 p->inodes_free = fsp->fsu_ffree; /* Free file nodes. */ 1087 p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail;
1088 p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */
1089 p->inodes_used = fsp->fsu_files - fsp->fsu_ffree;
1090 if (freespace_ignore_reserved) {
1091 /* option activated : we substract the root-reserved inodes from the total */
1092 /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */
1093 /* for others, fsp->fsu_ffree == fsp->fsu_favail */
1094 p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free;
1095 } else {
1096 /* default behaviour : take all the inodes into account */
1097 p->inodes_total = fsp->fsu_files;
1098 }
1055 np_add_name(&seen, p->best_match->me_mountdir); 1099 np_add_name(&seen, p->best_match->me_mountdir);
1056} 1100}