Module: check_mk
Branch: master
Commit: ffef7c3e4bf40a8d464280836115d916d0ffcdb5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ffef7c3e4bf40a…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Mar 12 17:10:30 2012 +0100
New version of statistics PIE
---
web/.f12 | 2 +-
web/htdocs/dashboard.css | 10 +++++
web/htdocs/dashboard.py | 79 +++++++++++++++++++++++++++---------------
web/htdocs/images/globe.png | Bin 0 -> 10926 bytes
4 files changed, 62 insertions(+), 29 deletions(-)
diff --git a/web/.f12 b/web/.f12
index eb354ad..ab3747a 100644
--- a/web/.f12
+++ b/web/.f12
@@ -2,4 +2,4 @@
SITE=${SITE:-$(omd sites --bare | head -n 1)}
C=$(sudo cp --preserve=mode -rv * /omd/versions/default/share/check_mk/web/ | wc -l)
echo "$C files copied"
-sudo omd restart $SITE apache
+# sudo omd restart $SITE apache
diff --git a/web/htdocs/dashboard.css b/web/htdocs/dashboard.css
index 9aceab3..5adbcd4 100644
--- a/web/htdocs/dashboard.css
+++ b/web/htdocs/dashboard.css
@@ -139,6 +139,16 @@ table.dashlet_overview h2 {
canvas.pie {
margin-top: 10px;
margin-left: 10px;
+ z-index: 20;
+}
+
+img.globe {
+ position: absolute;
+ top: 10px;
+ left: 10px;
+}
+img.globe {
+ z-index: 10;
}
div.dashlet table.hoststats {
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 5c4b666..ce2ccf9 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -452,6 +452,19 @@ def dashlet_servicestats():
"Stats: host_has_been_checked = 1\n" \
"StatsAnd: 5\n"),
+ ( _("in downtime"), "#0af",
+ "searchsvc&is_in_downtime=1",
+ "Stats: scheduled_downtime_depth > 0\n" \
+ "Stats: host_scheduled_downtime_depth > 0\n" \
+ "StatsOr: 2\n"),
+
+ ( _("on down host"), "#048",
+ "searchsvc&hst1=on&hst2=on&hstp=on&is_in_downtime=0",
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "Stats: host_scheduled_downtime_depth = 0\n" \
+ "Stats: host_state != 0\n" \
+ "StatsAnd: 3\n"),
+
( _("warning"), "#ff0",
"searchsvc&hst0=on&st1=on&is_in_downtime=0",
"Stats: state = 1\n" \
@@ -478,19 +491,6 @@ def dashlet_servicestats():
"Stats: host_state = 0\n" \
"Stats: host_has_been_checked = 1\n" \
"StatsAnd: 5\n"),
-
- ( _("in downtime"), "#0af",
- "searchsvc&is_in_downtime=1",
- "Stats: scheduled_downtime_depth > 0\n" \
- "Stats: host_scheduled_downtime_depth > 0\n" \
- "StatsOr: 2\n"),
-
- ( _("on down host"), "#048",
- "searchsvc&hst1=on&hst2=on&hstp=on&is_in_downtime=0",
- "Stats: scheduled_downtime_depth = 0\n" \
- "Stats: host_scheduled_downtime_depth = 0\n" \
- "Stats: host_state != 0\n" \
- "StatsAnd: 3\n"),
]
filter = "Filter: host_custom_variable_names < _REALNAME\n"
@@ -498,6 +498,10 @@ def dashlet_servicestats():
def render_statistics(pie_id, what, table, filter):
+ pie_diameter = 130
+ pie_left_aspect = 0.4
+ pie_right_aspect = 0.8
+
# Is the query restricted to a certain WATO-path?
wato_folder = html.var("wato_folder")
if wato_folder:
@@ -512,10 +516,10 @@ def render_statistics(pie_id, what, table, filter):
result = html.live.query_summed_stats(query)
pies = zip(table, result)
total = sum([x[1] for x in pies])
- pie_diameter = 136
- html.write('<canvas class=pie width=%d height=%d id=%s_stats
style="float: left"></canvas>' %
+ html.write('<canvas class=pie width=%d height=%d id="%s_stats"
style="float: left"></canvas>' %
(pie_diameter, pie_diameter, pie_id))
+ html.write('<img src="images/globe.png"
class="globe">')
html.write('<table class="hoststats%s"
style="float:left">' % (
len(pies) > 5 and " narrow" or ""))
@@ -534,30 +538,49 @@ def render_statistics(pie_id, what, table, filter):
r = 0.0
pie_parts = []
if total > 0:
- for (name, color, viewurl, q), value in pies:
- perc = 100.0 * value / total
- pie_parts.append('chart_pie("%s", %f, %f, %r);' % (pie_id,
r, r + perc, color))
- r += perc
+ # Counter number of non-zero classes
+ num_nonzero = 0
+ for info, value in pies:
+ if value > 0:
+ num_nonzero += 1
+
+ # Each non-zero class gets at least a view pixels of visible thickness
+ separator = 0.05 # 5% of radius
+ rest_radius = 1 - num_nonzero * separator
+
+ # Make sure, that each class that is not zero has at least a certain
+ # amount so that it will be visible
+ totalpart = 1
+ # Loop over classes, begin with red (most inner ball)
+ sum_separator = num_nonzero * separator
+ for (name, color, viewurl, q), value in pies[::1]:
+ part = float(value) / total
+ if value > 0 and totalpart > 0:
+ radius = sum_separator + rest_radius * totalpart ** (1/3.0)
+ pie_parts.append('chart_pie("%s", %f, %f, %r);' %
(pie_id, pie_right_aspect, radius, color))
+ pie_parts.append('chart_pie("%s", -%f, %f, %r);' %
(pie_id, pie_left_aspect, radius, color))
+ totalpart -= part
+ sum_separator -= separator
+
html.javascript("""
-function chart_pie(pie_id, from, to, color) {
+function chart_pie(pie_id, x_scale, radius, color) {
var context = document.getElementById(pie_id +
"_stats").getContext('2d');
if (!context)
return;
var pie_x = %(x)f;
var pie_y = %(y)f;
var pie_d = %(d)f;
+ context.fillStyle = color;
+ context.save();
+ context.translate(pie_x, pie_y);
+ context.scale(x_scale, 1);
context.beginPath();
- context.moveTo(pie_x, pie_y);
- context.arc(pie_x, pie_y, pie_d / 2 - 2, rad(from), rad(to), false);
+ context.moveTo(0, 0);
+ context.arc(0, 0, (pie_d / 2) * radius, 1.5 * Math.PI, 0.5 * Math.PI, false);
context.closePath();
- context.fillStyle = color;
- context.shadowOffsetX = 5;
- context.shadowOffsetY = 5;
- context.shadowBlur = 10;
- context.strokeStyle = "#ffffff";
context.fill();
- context.stroke();
+ context.restore();
context = null;
}
diff --git a/web/htdocs/images/globe.png b/web/htdocs/images/globe.png
new file mode 100644
index 0000000..e8ae881
Binary files /dev/null and b/web/htdocs/images/globe.png differ