[monitoring-plugins] [check_disk] add support to display inodes usage ...

Vincent Danjean git at monitoring-plugins.org
Tue Feb 19 21:50:15 CET 2019


    Module: monitoring-plugins
    Branch: master
    Commit: 270e7cba3830328424e3f2b6b9a6989b1ea5f89b
    Author: Vincent Danjean <vdanjean at debian.org>
 Committer: Vincent Danjean <Vincent.Danjean at ens-lyon.org>
      Date: Sat Dec  8 21:51:05 2018 +0100
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=270e7cb

[check_disk] add support to display inodes usage in perfdata

This is not enabled by default
It can be enabled with the -P (--iperfdata) option

---

 gl/fsusage.c         |  5 +++++
 gl/fsusage.h         |  3 ++-
 lib/utils_disk.c     |  2 ++
 lib/utils_disk.h     |  3 ++-
 plugins/check_disk.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/gl/fsusage.c b/gl/fsusage.c
index 0657555..6103ecf 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)
       fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0;
       fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files);
       fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree);
+      fsp->fsu_favail = PROPAGATE_ALL_ONES (vfsd.f_favail);
       return 0;
     }
 
@@ -174,6 +175,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
   fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0;
   fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot);
   fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
+  fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
 
 #elif defined STAT_READ_FILSYS          /* SVR2 */
 # ifndef SUPERBOFF
@@ -209,6 +211,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
                     ? UINTMAX_MAX
                     : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1));
   fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode);
+  fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.s_tinode);
 
 #elif defined STAT_STATFS3_OSF1         /* OSF/1 */
 
@@ -296,6 +299,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
   fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0;
   fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files);
   fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree);
+  fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.f_ffree);
 
 #endif
 
@@ -323,6 +327,7 @@ statfs (char *file, struct statfs *fsb)
   fsb->f_bavail = fsd.du_tfree;
   fsb->f_files  = (fsd.du_isize - 2) * fsd.du_inopb;
   fsb->f_ffree  = fsd.du_tinode;
+  fsb->f_favail  = fsd.du_tinode;
   fsb->f_fsid.val[0] = fsd.du_site;
   fsb->f_fsid.val[1] = fsd.du_pckno;
   return 0;
diff --git a/gl/fsusage.h b/gl/fsusage.h
index 7810fc0..e2654fd 100644
--- a/gl/fsusage.h
+++ b/gl/fsusage.h
@@ -32,7 +32,8 @@ struct fs_usage
   uintmax_t fsu_bavail;         /* Free blocks available to non-superuser. */
   bool fsu_bavail_top_bit_set;  /* 1 if fsu_bavail represents a value < 0.  */
   uintmax_t fsu_files;          /* Total file nodes. */
-  uintmax_t fsu_ffree;          /* Free file nodes. */
+  uintmax_t fsu_ffree;          /* Free file nodes to superuser. */
+  uintmax_t fsu_favail;         /* Free file nodes to non-superuser. */
 };
 
 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 efe35fc..c7c9126 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)
   new_path->dtotal_units = 0;
   new_path->inodes_total = 0;
   new_path->inodes_free = 0;
+  new_path->inodes_free_to_root = 0;
+  new_path->inodes_used = 0;
   new_path->dused_inodes_percent = 0;
   new_path->dfree_inodes_percent = 0;
 
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 83a3763..999270c 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -24,7 +24,8 @@ struct parameter_list
   char *group;
   struct mount_entry *best_match;
   struct parameter_list *name_next;
-  uintmax_t total, available, available_to_root, used, inodes_free, inodes_total;
+  uintmax_t total, available, available_to_root, used,
+    inodes_free, inodes_free_to_root, inodes_used, inodes_total;
   double dfree_pct, dused_pct;
   double dused_units, dfree_units, dtotal_units;
   double dused_inodes_percent, dfree_inodes_percent;
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;
 int display_mntp = FALSE;
 int exact_match = FALSE;
 int freespace_ignore_reserved = FALSE;
+int display_inodes_perfdata = FALSE;
 char *warn_freespace_units = NULL;
 char *crit_freespace_units = NULL;
 char *warn_freespace_percent = NULL;
@@ -167,6 +168,7 @@ main (int argc, char **argv)
   char *output;
   char *details;
   char *perf;
+  char *perf_ilabel;
   char *preamble;
   char *flag_header;
   double inode_space_pct;
@@ -186,6 +188,7 @@ main (int argc, char **argv)
   output = strdup ("");
   details = strdup ("");
   perf = strdup ("");
+  perf_ilabel = strdup ("");
   stat_buf = malloc(sizeof *stat_buf);
 
   setlocale (LC_ALL, "");
@@ -348,6 +351,29 @@ main (int argc, char **argv)
                           TRUE, 0,
                           TRUE, path->dtotal_units));
 
+      if (display_inodes_perfdata) {
+        /* *_high_tide must be reinitialized at each run */
+        warning_high_tide = UINT_MAX;
+        critical_high_tide = UINT_MAX;
+
+        if (path->freeinodes_percent->warning != NULL) {
+          warning_high_tide = abs( min( (double) warning_high_tide, (double) (1.0 - path->freeinodes_percent->warning->end/100)*path->inodes_total ));
+        }
+        if (path->freeinodes_percent->critical != NULL) {
+          critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freeinodes_percent->critical->end/100)*path->inodes_total ));
+        }
+
+        xasprintf (&perf_ilabel, "%s (inodes)", (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir);
+        /* Nb: *_high_tide are unset when == UINT_MAX */
+        xasprintf (&perf, "%s %s", perf,
+                   perfdata (perf_ilabel,
+                             path->inodes_used, "",
+                             (warning_high_tide != UINT_MAX ? TRUE : FALSE), warning_high_tide,
+                             (critical_high_tide != UINT_MAX ? TRUE : FALSE), critical_high_tide,
+                             TRUE, 0,
+                             TRUE, path->inodes_total));
+      }
+
       if (disk_result==STATE_OK && erronly && !verbose)
         continue;
 
@@ -455,6 +481,7 @@ process_arguments (int argc, char **argv)
     {"ignore-eregi-partition", required_argument, 0, 'I'},
     {"local", no_argument, 0, 'l'},
     {"stat-remote-fs", no_argument, 0, 'L'},
+    {"iperfdata", no_argument, 0, 'P'},
     {"mountpoint", no_argument, 0, 'M'},
     {"errors-only", no_argument, 0, 'e'},
     {"exact-match", no_argument, 0, 'E'},
@@ -477,7 +504,7 @@ process_arguments (int argc, char **argv)
       strcpy (argv[c], "-t");
 
   while (1) {
-    c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option);
+    c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEA", longopts, &option);
 
     if (c == -1 || c == EOF)
       break;
@@ -582,9 +609,13 @@ process_arguments (int argc, char **argv)
       break;
     case 'L':
       stat_remote_fs = 1;
+      /* fallthrough */
     case 'l':
       show_local_fs = 1;
       break;
+    case 'P':
+      display_inodes_perfdata = 1;
+      break;
     case 'p':                 /* select path */
       if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
              crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
@@ -1012,6 +1043,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
           p->dtotal_units += p_list->dtotal_units;
           p->inodes_total += p_list->inodes_total;
           p->inodes_free  += p_list->inodes_free;
+          p->inodes_free_to_root  += p_list->inodes_free_to_root;
+          p->inodes_used  += p_list->inodes_used;
         }
         first = 0;
       }
@@ -1050,7 +1083,18 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
   p->dused_units = p->used*fsp->fsu_blocksize/mult;
   p->dfree_units = p->available*fsp->fsu_blocksize/mult;
   p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
-  p->inodes_total = fsp->fsu_files;      /* Total file nodes. */
-  p->inodes_free  = fsp->fsu_ffree;      /* Free file nodes. */
+  /* Free file nodes. Not sure the workaround is required, but in case...*/
+  p->inodes_free  = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail;
+  p->inodes_free_to_root  = fsp->fsu_ffree; /* Free file nodes for root. */
+  p->inodes_used = fsp->fsu_files - fsp->fsu_ffree;
+  if (freespace_ignore_reserved) {
+    /* option activated : we substract the root-reserved inodes from the total */
+    /* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */
+    /* for others, fsp->fsu_ffree == fsp->fsu_favail */
+    p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free;
+  } else {
+    /* default behaviour : take all the inodes into account */
+    p->inodes_total = fsp->fsu_files;
+  }
   np_add_name(&seen, p->best_match->me_mountdir);
 }



More information about the Commits mailing list