Module: check_mk
Branch: master
Commit: 1ec1aa32928957b3e12eddea4602841e333c9367
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1ec1aa32928957…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Nov 12 10:48:35 2013 +0100
Cleaned up byte format helpers - use get_filesize_human_readable really only for files
---
checks/cisco_mem | 4 ++--
checks/netapp_fcpio | 4 ++--
modules/check_mk_base.py | 7 +++++--
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/checks/cisco_mem b/checks/cisco_mem
index cc1199c..9034ebe 100644
--- a/checks/cisco_mem
+++ b/checks/cisco_mem
@@ -50,7 +50,7 @@ def check_cisco_mem_sub(params, mem_used, mem_total):
if type(warn) == float:
infotext = "%2.1f%% (%s) of %s used" % \
- (perc_used, get_filesize_human_readable(mem_used),
get_filesize_human_readable(mem_total))
+ (perc_used, get_bytes_human_readable(mem_used),
get_bytes_human_readable(mem_total))
if perc_used >= crit:
return (2, infotext + " (critical at %d%%)" % crit, perfdata)
elif perc_used >= warn:
@@ -59,7 +59,7 @@ def check_cisco_mem_sub(params, mem_used, mem_total):
return (0, infotext, perfdata)
else:
infotext = "%s (%2.1f%%) of %s used" % \
- (get_filesize_human_readable(mem_used), perc_used,
get_filesize_human_readable(mem_total))
+ (get_bytes_human_readable(mem_used), perc_used,
get_bytes_human_readable(mem_total))
if mem_used >= crit:
return (2, infotext + " (critical at %s MB)" % crit, perfdata)
elif mem_used >= warn:
diff --git a/checks/netapp_fcpio b/checks/netapp_fcpio
index 3e474c4..af7b952 100644
--- a/checks/netapp_fcpio
+++ b/checks/netapp_fcpio
@@ -56,8 +56,8 @@ def check_netapp_fcpio(item, params, info):
write_msg = ' (!!)'
- infotext = "%s read%s, %s write%s in last %d sec" %
(get_filesize_human_readable(avg_read), \
- read_msg, get_filesize_human_readable(avg_write), write_msg, timedif)
+ infotext = "%s read%s, %s write%s in last %d sec" %
(get_bytes_human_readable(avg_read), \
+ read_msg, get_bytes_human_readable(avg_write), write_msg, timedif)
return(state, infotext, perfdata)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index b4db04e..a1a5f60 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1486,10 +1486,13 @@ def get_bytes_human_readable(b, base=1024.0, bytefrac=True,
unit="B"):
return '%s%.0f%s' % (prefix, b, unit)
# Similar to get_bytes_human_readable, but optimized for file
-# sizes
+# sizes. Really only use this for files. We assume that for smaller
+# files one wants to compare the exact bytes of a file, so the
+# threshold to show the value as MB/GB is higher as the one of
+# get_bytes_human_readable().
def get_filesize_human_readable(size):
if size < 4 * 1024 * 1024:
- return str(size)
+ return "%dB" % int(size)
elif size < 4 * 1024 * 1024 * 1024:
return "%.2fMB" % (float(size) / (1024 * 1024))
else: