فهرست منبع

check_disk: alerts issued too soon

Fix for issue #195

The percentage calculated for used space does effectively a ceil(p)
call. So if used space is 89.01% it would get set to 90%. Free space
percentage is `100 - usedspace%`. With a warning threshold of 10%,
a warning would be triggered when there was 10.9% free. So on a
partition of 100GB, a warning would be triggered 100MB before the
actual threshold.

I changed the used space percentage calculation to calculate to
two decimal points, which prevents a warning or critical condition
from being triggered until much closer to the specified thresholds.
John C. Frickson 9 سال پیش
والد
کامیت
4cd52f89ec
1فایلهای تغییر یافته به همراه6 افزوده شده و 6 حذف شده
  1. 6 6
      plugins/check_disk.c

+ 6 - 6
plugins/check_disk.c

@@ -363,7 +363,7 @@ main (int argc, char **argv)
       else {
 	      xasprintf(&flag_header, "");
       }
-      xasprintf (&output, "%s %s %.0f %s (%.0f%%",
+      xasprintf (&output, "%s %s %.0f %s (%.2f%%",
                 output,
                 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
                 path->dfree_units,
@@ -414,17 +414,17 @@ double calculate_percent(uintmax_t value, uintmax_t total) {
   double pct = -1;
   /* I don't understand the below, but it is taken from coreutils' df */
   /* Seems to be calculating pct, in the best possible way */
-  if (value <= TYPE_MAXIMUM(uintmax_t) / 100
+  if (value <= TYPE_MAXIMUM(uintmax_t) / 10000
     && total != 0) {
-    uintmax_t u100 = value * 100;
-    pct = u100 / total + (u100 % total != 0);
+    uintmax_t u100 = value * 10000;
+    pct = (u100 / total + (u100 % total != 0)) / 100.0;
   } else {
     /* Possible rounding errors - see coreutils' df for more explanation */
     double u = value;
     double t = total;
     if (t) {
-      long int lipct = pct = u * 100 / t;
-      double ipct = lipct;
+      long int lipct = pct = u * 10000 / t;
+      double ipct = lipct / 100.0;
 
       /* Like 'pct = ceil (dpct);', but without ceil - from coreutils again */
       if (ipct - 1 < pct && pct <= ipct + 1)