diff options
author | Sven Nierlein <sven@nierlein.org> | 2019-02-19 21:49:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-19 21:49:13 +0100 |
commit | 555559fd303825e02c0aa196194ae15a2e88aadc (patch) | |
tree | abebf547da25660bd158896bef8420de72811d55 | |
parent | 931ed78b5dc062fff33652d87406f1547da5ddbe (diff) | |
parent | 270e7cba3830328424e3f2b6b9a6989b1ea5f89b (diff) | |
download | monitoring-plugins-555559fd303825e02c0aa196194ae15a2e88aadc.tar.gz |
Merge pull request #1567 from vdanjean/master
[check_disk] add support to display inodes usage in perfdata
-rw-r--r-- | gl/fsusage.c | 5 | ||||
-rw-r--r-- | gl/fsusage.h | 3 | ||||
-rw-r--r-- | lib/utils_disk.c | 2 | ||||
-rw-r--r-- | lib/utils_disk.h | 3 | ||||
-rw-r--r-- | plugins/check_disk.c | 50 |
5 files changed, 58 insertions, 5 deletions
diff --git a/gl/fsusage.c b/gl/fsusage.c index 0657555f..6103ecf3 100644 --- a/gl/fsusage.c +++ b/gl/fsusage.c | |||
@@ -143,6 +143,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
143 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; | 143 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; |
144 | fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); | 144 | fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); |
145 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); | 145 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); |
146 | fsp->fsu_favail = PROPAGATE_ALL_ONES (vfsd.f_favail); | ||
146 | return 0; | 147 | return 0; |
147 | } | 148 | } |
148 | 149 | ||
@@ -174,6 +175,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
174 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0; | 175 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0; |
175 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); | 176 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); |
176 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); | 177 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); |
178 | fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); | ||
177 | 179 | ||
178 | #elif defined STAT_READ_FILSYS /* SVR2 */ | 180 | #elif defined STAT_READ_FILSYS /* SVR2 */ |
179 | # ifndef SUPERBOFF | 181 | # ifndef SUPERBOFF |
@@ -209,6 +211,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
209 | ? UINTMAX_MAX | 211 | ? UINTMAX_MAX |
210 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); | 212 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); |
211 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); | 213 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); |
214 | fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.s_tinode); | ||
212 | 215 | ||
213 | #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ | 216 | #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ |
214 | 217 | ||
@@ -296,6 +299,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) | |||
296 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; | 299 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; |
297 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); | 300 | fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); |
298 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); | 301 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); |
302 | fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.f_ffree); | ||
299 | 303 | ||
300 | #endif | 304 | #endif |
301 | 305 | ||
@@ -323,6 +327,7 @@ statfs (char *file, struct statfs *fsb) | |||
323 | fsb->f_bavail = fsd.du_tfree; | 327 | fsb->f_bavail = fsd.du_tfree; |
324 | fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; | 328 | fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; |
325 | fsb->f_ffree = fsd.du_tinode; | 329 | fsb->f_ffree = fsd.du_tinode; |
330 | fsb->f_favail = fsd.du_tinode; | ||
326 | fsb->f_fsid.val[0] = fsd.du_site; | 331 | fsb->f_fsid.val[0] = fsd.du_site; |
327 | fsb->f_fsid.val[1] = fsd.du_pckno; | 332 | fsb->f_fsid.val[1] = fsd.du_pckno; |
328 | return 0; | 333 | return 0; |
diff --git a/gl/fsusage.h b/gl/fsusage.h index 7810fc01..e2654fd8 100644 --- a/gl/fsusage.h +++ b/gl/fsusage.h | |||
@@ -32,7 +32,8 @@ struct fs_usage | |||
32 | uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ | 32 | uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ |
33 | bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ | 33 | bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ |
34 | uintmax_t fsu_files; /* Total file nodes. */ | 34 | uintmax_t fsu_files; /* Total file nodes. */ |
35 | uintmax_t fsu_ffree; /* Free file nodes. */ | 35 | uintmax_t fsu_ffree; /* Free file nodes to superuser. */ |
36 | uintmax_t fsu_favail; /* Free file nodes to non-superuser. */ | ||
36 | }; | 37 | }; |
37 | 38 | ||
38 | int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); | 39 | int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp); |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index efe35fc5..c7c9126e 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -69,6 +69,8 @@ np_add_parameter(struct parameter_list **list, const char *name) | |||
69 | new_path->dtotal_units = 0; | 69 | new_path->dtotal_units = 0; |
70 | new_path->inodes_total = 0; | 70 | new_path->inodes_total = 0; |
71 | new_path->inodes_free = 0; | 71 | new_path->inodes_free = 0; |
72 | new_path->inodes_free_to_root = 0; | ||
73 | new_path->inodes_used = 0; | ||
72 | new_path->dused_inodes_percent = 0; | 74 | new_path->dused_inodes_percent = 0; |
73 | new_path->dfree_inodes_percent = 0; | 75 | new_path->dfree_inodes_percent = 0; |
74 | 76 | ||
diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 83a37639..999270cd 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h | |||
@@ -24,7 +24,8 @@ struct parameter_list | |||
24 | char *group; | 24 | char *group; |
25 | struct mount_entry *best_match; | 25 | struct mount_entry *best_match; |
26 | struct parameter_list *name_next; | 26 | struct parameter_list *name_next; |
27 | uintmax_t total, available, available_to_root, used, inodes_free, inodes_total; | 27 | uintmax_t total, available, available_to_root, used, |
28 | inodes_free, inodes_free_to_root, inodes_used, inodes_total; | ||
28 | double dfree_pct, dused_pct; | 29 | double dfree_pct, dused_pct; |
29 | double dused_units, dfree_units, dtotal_units; | 30 | double dused_units, dfree_units, dtotal_units; |
30 | double dused_inodes_percent, dfree_inodes_percent; | 31 | double dused_inodes_percent, dfree_inodes_percent; |
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index e73a0083..1c43e854 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -141,6 +141,7 @@ int erronly = FALSE; | |||
141 | int display_mntp = FALSE; | 141 | int display_mntp = FALSE; |
142 | int exact_match = FALSE; | 142 | int exact_match = FALSE; |
143 | int freespace_ignore_reserved = FALSE; | 143 | int freespace_ignore_reserved = FALSE; |
144 | int display_inodes_perfdata = FALSE; | ||
144 | char *warn_freespace_units = NULL; | 145 | char *warn_freespace_units = NULL; |
145 | char *crit_freespace_units = NULL; | 146 | char *crit_freespace_units = NULL; |
146 | char *warn_freespace_percent = NULL; | 147 | char *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 | } |