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.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index c6bba24..0d84ecd 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -46,7 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
46#include <stdarg.h> 46#include <stdarg.h>
47#include "fsusage.h" 47#include "fsusage.h"
48#include "mountlist.h" 48#include "mountlist.h"
49#include "intprops.h" /* necessary for TYPE_MAXIMUM */ 49#include <float.h>
50#if HAVE_LIMITS_H 50#if HAVE_LIMITS_H
51# include <limits.h> 51# include <limits.h>
52#endif 52#endif
@@ -325,7 +325,7 @@ main (int argc, char **argv)
325 get_stats (path, &fsp); 325 get_stats (path, &fsp);
326 326
327 if (verbose >= 3) { 327 if (verbose >= 3) {
328 printf ("For %s, used_pct=%g free_pct=%g used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%lu mult=%lu\n", 328 printf ("For %s, used_pct=%f free_pct=%f used_units=%lu free_units=%lu total_units=%lu used_inodes_pct=%f free_inodes_pct=%f fsp.fsu_blocksize=%lu mult=%lu\n",
329 me->me_mountdir, 329 me->me_mountdir,
330 path->dused_pct, 330 path->dused_pct,
331 path->dfree_pct, 331 path->dfree_pct,
@@ -431,7 +431,7 @@ main (int argc, char **argv)
431 } else { 431 } else {
432 xasprintf(&flag_header, ""); 432 xasprintf(&flag_header, "");
433 } 433 }
434 xasprintf (&output, "%s%s %s %llu%s (%.0f%%", 434 xasprintf (&output, "%s%s %s %llu%s (%.1f%%",
435 output, flag_header, 435 output, flag_header,
436 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 436 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
437 path->dfree_units, 437 path->dfree_units,
@@ -461,24 +461,8 @@ main (int argc, char **argv)
461 461
462double calculate_percent(uintmax_t value, uintmax_t total) { 462double calculate_percent(uintmax_t value, uintmax_t total) {
463 double pct = -1; 463 double pct = -1;
464 /* I don't understand the below, but it is taken from coreutils' df */ 464 if(value <= DBL_MAX && total != 0) {
465 /* Seems to be calculating pct, in the best possible way */ 465 pct = (double)value / total * 100.0;
466 if (value <= TYPE_MAXIMUM(uintmax_t) / 100
467 && total != 0) {
468 uintmax_t u100 = value * 100;
469 pct = u100 / total + (u100 % total != 0);
470 } else {
471 /* Possible rounding errors - see coreutils' df for more explanation */
472 double u = value;
473 double t = total;
474 if (t) {
475 long int lipct = pct = u * 100 / t;
476 double ipct = lipct;
477
478 /* Like 'pct = ceil (dpct);', but without ceil - from coreutils again */
479 if (ipct - 1 < pct && pct <= ipct + 1)
480 pct = ipct + (ipct < pct);
481 }
482 } 466 }
483 return pct; 467 return pct;
484} 468}
@@ -1130,7 +1114,7 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
1130 } 1114 }
1131 /* finally calculate percentages for either plain FS or summed up group */ 1115 /* finally calculate percentages for either plain FS or summed up group */
1132 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */ 1116 p->dused_pct = calculate_percent( p->used, p->used + p->available ); /* used + available can never be > uintmax */
1133 p->dfree_pct = 100 - p->dused_pct; 1117 p->dfree_pct = 100.0 - p->dused_pct;
1134 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total); 1118 p->dused_inodes_percent = calculate_percent(p->inodes_total - p->inodes_free, p->inodes_total);
1135 p->dfree_inodes_percent = 100 - p->dused_inodes_percent; 1119 p->dfree_inodes_percent = 100 - p->dused_inodes_percent;
1136 1120