Module: check_mk
Branch: master
Commit: 0f3c1dd6f41e4b827d04c81d10a7f0b07ff24b0a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0f3c1dd6f41e4b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Mar 24 17:05:19 2015 +0100
age_human_readable: fix exception for times < 1 pico second
---
web/htdocs/check_mk.css | 4 ++--
web/htdocs/lib.py | 31 ++++++++++++++++++++-----------
web/htdocs/metrics.py | 6 +++++-
web/plugins/metrics/check_mk.py | 2 +-
4 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index 3716ec6..acfeeb4 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -597,7 +597,7 @@ table.graph tr > td.legend > table th.scalar {
color: black;
text-align: right;
padding-bottom: 3px;
- border-bottom: 0.6px solid #000;
+ border-bottom: 1px solid #000;
color: #888;
font-weight: bold;
}
@@ -611,7 +611,7 @@ table.graph tr > td.legend > table td.scalar {
}
table.graph tr > td.legend > table > tbody > tr.scalar.first {
- border-top: 0.6px solid #000;
+ border-top: 1px solid #000;
}
table.graph tr > td.legend > table > tbody > tr.scalar.first td {
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index 14ddbd8..df64ec7 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -529,32 +529,35 @@ def physical_precision(v, precision, unit_symbol):
# Choose a power where no artifical zero (due to rounding) needs to be
# placed left of the decimal point.
scale_symbols = {
+ -5 : "f",
-4 : "p",
-3 : "n",
-2 : u"µ",
-1 : "m",
- 0 : "",
- 1 : "K",
- 2 : "M",
- 3 : "G",
- 4 : "T",
- 5 : "P",
+ 0 : "",
+ 1 : "K",
+ 2 : "M",
+ 3 : "G",
+ 4 : "T",
+ 5 : "P",
}
scale = 0
- while exponent < 0:
+ while exponent < 0 and scale > -5:
scale -= 1
exponent += 3
# scale, exponent = divmod(exponent, 3)
places_before_comma = exponent + 1
places_after_comma = precision - places_before_comma
- while places_after_comma < 0:
+ while places_after_comma < 0 and scale < 5:
scale += 1
exponent -= 3
places_before_comma = exponent + 1
places_after_comma = precision - places_before_comma
+
value = mantissa * 10**exponent
+
return u"%%.%df %%s%%s" % places_after_comma % (value,
scale_symbols[scale], unit_symbol)
@@ -578,8 +581,6 @@ def number_human_readable(n, precision=1, unit="B"):
def age_human_readable(secs, min_only=False):
if secs < 0:
return "- " + age_human_readable(-secs, min_only)
- elif secs > 0 and secs < 0.0001: # us
- return "%.1f us" % (secs * 1000000)
elif secs > 0 and secs < 1: # ms
return physical_precision(secs, 3, _("s"))
elif min_only:
@@ -601,8 +602,16 @@ def age_human_readable(secs, min_only=False):
if days < 6:
d = ("%.1f" % days).rstrip("0").rstrip(".")
return "%s %s" % (d, _("days"))
- else:
+ elif days < 999:
return "%.0f %s" % (days, _("days"))
+ else:
+ years = days / 365
+ if years < 10:
+ return "%.1f %s" % (years, _("years"))
+ else:
+ return "%.0f %s" % (years, _("years"))
+
+
def bytes_human_readable(b, base=1024.0, bytefrac=True, unit="B"):
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 6957e93..0e05b5c 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -94,7 +94,11 @@ scalar_colors = {
# Convert perf_data_string into perf_data, extract check_command
def parse_perf_data(perf_data_string, check_command=None):
+ if not perf_data_string:
+ return {}, check_command
+
parts = perf_data_string.split()
+
# Try if check command is appended to performance data
# in a PNP like style
if parts[-1].startswith("[") and parts[-1].endswith("]"):
@@ -312,7 +316,7 @@ def evaluate_rpn(expression, translated_metrics):
def evaluate_literal(expression, translated_metrics):
if type(expression) == int:
- return expression, unit_info["count"], None
+ return float(expression), unit_info["count"], None
elif type(expression) == float:
return expression, unit_info[""], None
diff --git a/web/plugins/metrics/check_mk.py b/web/plugins/metrics/check_mk.py
index c53b4c1..217fd96 100644
--- a/web/plugins/metrics/check_mk.py
+++ b/web/plugins/metrics/check_mk.py
@@ -1097,7 +1097,7 @@ graph_info.append({
( "user,system,io_wait,+,+#004080", "line",
_("Total") ),
],
"mirror_legend" : True,
- # "range" : (0, 100),
+ "range" : (0, 100),
})
graph_info.append({