e.g. CPU load)
Message-ID: <56e1562f.1g2Rv0e1skiGUdKf%mk(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 9b9b4365ba3f1e9e7fcce496440185d7212e441a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9b9b4365ba3f1e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Mar 10 12:10:22 2016 +0100
3269 FIX Fix rendering of floating point values < 1 in graphs (e.g. CPU load)
---
.werks/3269 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/lib.py | 28 ++++++++++++++++++++++++++++
web/plugins/metrics/check_mk.py | 2 +-
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/.werks/3269 b/.werks/3269
new file mode 100644
index 0000000..c614186
--- /dev/null
+++ b/.werks/3269
@@ -0,0 +1,10 @@
+Title: Fix rendering of floating point values < 1 in graphs (e.g. CPU load)
+Level: 2
+Component: reporting
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1457608199
+
+
diff --git a/ChangeLog b/ChangeLog
index 90dd0b7..179a138 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -134,6 +134,7 @@
* 3267 New availability option for reclassifying host state
"unreachable"...
* 3249 FIX: Fix missing filter for non-OK services when report is called via context
button
* 3268 FIX: Availability options were invalid after resetting them...
+ * 3269 FIX: Fix rendering of floating point values < 1 in graphs (e.g. CPU load)
Event Console:
* 2999 The contact name is now included in Event Console notifications...
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index aa58e0a..8f4f09d 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -620,6 +620,34 @@ def drop_dotzero(v, digits=1):
return t
+# Renders a floating point number with the given number
+# of non-zero digits. Example if precision is 3:
+# 12.40349034 -> 12.4
+# 1.23894859348563478 -> 1.24
+# 0.00001239898568978 -> 0.0000124
+# 12400000.00230923 -> 12400000
+
+def render_float_with_precision(value, precision):
+ if value == 0:
+ return "0"
+
+ elif value < 0:
+ return "-" + render_float_with_precision(-value, precision)
+
+ mantissa, exponent = frexp10(float(value))
+ # exponent + 1 is the number of digits left of the .
+
+ # Digits left of . are more than precision -> no fraction.
+ if exponent + 1 >= precision:
+ return "%.0f" % value
+
+ # Allow so many digits after comma that we have at least 'precision'
+ # valid non-zero digits
+ else:
+ digits = precision - exponent - 1
+ return "%%.%df" % digits % value
+
+
def number_human_readable(n, precision=1, unit="B"):
base = 1024.0
if unit == "Bit":
diff --git a/web/plugins/metrics/check_mk.py b/web/plugins/metrics/check_mk.py
index 7433be8..c9aa20f 100644
--- a/web/plugins/metrics/check_mk.py
+++ b/web/plugins/metrics/check_mk.py
@@ -65,7 +65,7 @@ unit_info[""] = {
"title" : "",
"description" : _("Floating point number"),
"symbol" : "",
- "render" : lambda v: "%.2f" % v,
+ "render" : lambda v: render_float_with_precision(v, 3),
}
unit_info["count"] = {