Module: check_mk
Branch: master
Commit: 5894921ccdaf5857dc354d62fa2069c7858e2ce2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5894921ccdaf58…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 23 15:06:46 2015 +0100
New helper function for outputting % in defined precision
---
checks/df.include | 7 ++-----
modules/check_mk_base.py | 11 +++++++++++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/checks/df.include b/checks/df.include
index fa8f36d..dd667f9 100644
--- a/checks/df.include
+++ b/checks/df.include
@@ -319,11 +319,8 @@ def df_check_filesystem_single(hostname, mountpoint, size_mb,
avail_mb, reserved
# Show enough decimal digits so that very small percentages are still
# visible!
- if used_perc > 0:
- perc_precision = max(1, 2 - int(round(math.log(used_perc, 10))))
- else:
- perc_precision = 1
- infotext = "%%.%df%%%% used (%%s of %%s), %%s" % perc_precision %
(used_perc, used_hr, size_hr, levels["levels_text"])
+ infotext = "%s used (%s of %s), %s" % (
+ get_percent_human_readable(used_perc), used_hr, size_hr,
levels["levels_text"])
status = 0
if warn_mb <= -1:
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 33eb289..1051e85 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1904,6 +1904,17 @@ def get_age_human_readable(secs):
return "%d days %d hours" % (days, hours)
return "%d days" % days
+# Format perc (0 <= perc <= 100 + x) so that precision
+# digits are being displayed. This avoids a "0.00%" for
+# very small numbers
+def get_percent_human_readable(perc, precision=2):
+ if perc > 0:
+ perc_precision = max(1, 2 - int(round(math.log(perc, 10))))
+ else:
+ perc_precision = 1
+ return "%%.%df%%%%" % perc_precision % perc
+
+
# Quote string for use as arguments on the shell
def quote_shell_string(s):
return "'" + s.replace("'",
"'\"'\"'") + "'"