Module: check_mk
Branch: master
Commit: 968c84ba09a60bfe099617583a165e68933f8b2f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=968c84ba09a60b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Jun 26 11:59:40 2011 +0200
Multisite: improved dashboard
---
web/htdocs/check_mk.css | 38 ++++++++++++
web/htdocs/dashboard.py | 120 ++++++++++++++++++++++++++++++++++++++
web/htdocs/index.py | 5 +-
web/plugins/dashboard/builtin.py | 37 +++++++++---
web/plugins/pages/shipped.py | 2 +
web/plugins/views/dashboard.py | 6 +-
6 files changed, 194 insertions(+), 14 deletions(-)
diff --git a/web/htdocs/check_mk.css b/web/htdocs/check_mk.css
index 6999d53..bf1dbb5 100644
--- a/web/htdocs/check_mk.css
+++ b/web/htdocs/check_mk.css
@@ -1724,6 +1724,44 @@ table.dashlet_overview h2 {
font-size: 10pt;
}
+/* Styles for various builtin dashlets */
+canvas.pie {
+ margin-top: 10px;
+ margin-left: 10px;
+}
+
+table.hoststats {
+ margin-top: 10px;
+ margin-left: 5px;
+ width: 80px;
+ height: 136px;
+ border-collapse: collapse;
+ border-spacing: 0px;
+}
+table.hoststats td {
+ text-align: right;
+ padding-right: 6px;
+ padding-left: 6px;
+ background-image: url("images/form_background.png");
+ background-repeat: repeat;
+}
+table.hoststats th {
+ text-align: left;
+ background-color: transparent;
+ padding-right: 3em;
+ padding-left: 6px;
+}
+table.hoststats th, table.hoststats td {
+ padding-top: 3px;
+ padding-bottom: 3px;
+ border-color: white;
+ border-style: solid none;
+ border-width: 1px;
+ vertical-align: middle;
+}
+
+
+
/*
_ _ _ ____ _
/ \ __| | __| / ___| _ __ __ _ _ __ (_)_ __ ___
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index c4bb0cf..6e656bc 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -352,3 +352,123 @@ def dashlet_overview():
html.write('</tr></table>')
+
+def dashlet_hoststats():
+ table = [
+ ( _("Up"), "#0b3",
+ "Stats: state = 0\n" \
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "StatsAnd: 2\n"),
+
+ ( _("Down"), "#f00",
+ "Stats: state = 1\n" \
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "StatsAnd: 2\n"),
+
+ ( _("Unreachable"), "#f80",
+ "Stats: state = 2\n" \
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "StatsAnd: 2\n"),
+
+ ( _("In downtime"), "#0af",
+ "Stats: scheduled_downtime_depth > 0\n" \
+ )
+ ]
+ filter = "Filter: custom_variable_names < _REALNAME\n"
+
+ render_statistics("hosts", table, filter)
+
+def dashlet_servicestats():
+ table = [
+ ( _("Ok"), "#0b3",
+ "Stats: state = 0\n" \
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "Stats: host_scheduled_downtime_depth = 0\n" \
+ "StatsAnd: 3\n"),
+
+ ( _("Warning"), "#ff0",
+ "Stats: state = 1\n" \
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "Stats: host_scheduled_downtime_depth = 0\n" \
+ "StatsAnd: 3\n"),
+
+ ( _("Unknown"), "#f80",
+ "Stats: state = 3\n" \
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "Stats: host_scheduled_downtime_depth = 0\n" \
+ "StatsAnd: 3\n"),
+
+ ( _("Critical"), "#f00",
+ "Stats: state = 2\n" \
+ "Stats: scheduled_downtime_depth = 0\n" \
+ "Stats: host_scheduled_downtime_depth = 0\n" \
+ "StatsAnd: 3\n"),
+
+ ( _("In downtime"), "#0af",
+ "Stats: scheduled_downtime_depth > 0\n" \
+ "Stats: host_scheduled_downtime_depth > 0\n" \
+ "StatsOr: 2\n" \
+ )
+ ]
+ filter = "Filter: host_custom_variable_names < _REALNAME\n"
+
+ render_statistics("services", table, filter)
+
+def render_statistics(what, table, filter):
+ query = "GET %s\n" % what
+ for entry in table:
+ query += entry[2]
+ query += 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>' %
+ (pie_diameter, pie_diameter, what))
+
+ html.write('<table class=hoststats style="float:left">')
+ for (name, color, query), count in pies + [ ((_("Total"), "",
""), total) ]:
+
html.write("<tr><th>%s</th><td>%d</td></tr>"
% (name, count))
+
+ html.write("</table>")
+
+ html.javascript("""
+
+function chart_pie(from, to, color) {
+ context.beginPath();
+ context.moveTo(pie_x, pie_y);
+ context.arc(pie_x, pie_y, pie_d / 2 - 2, rad(from), rad(to), false);
+ context.closePath();
+ context.fillStyle = color;
+ context.shadowOffsetX = 5;
+ context.shadowOffsetY = 5;
+ context.shadowBlur = 10;
+ context.strokeStyle = "#ffffff";
+ context.fill();
+ context.stroke();
+}
+
+// convert percent to angle(rad)
+function rad(g) {
+ return (g * 360 / 100 * Math.PI) / 180;
+}
+
+pie_x = %(x)f;
+pie_y = %(y)f;
+pie_d = %(d)f;
+
+context = document.getElementById("%(what)s_stats").getContext('2d');
+
+""" % { "what" : what, "x" : pie_diameter / 2,
+ "y": pie_diameter/2, "d" : pie_diameter })
+
+
+ r = 0.0;
+ for (name, color, q), value in pies:
+ perc = 100.0 * value / total
+ html.javascript('chart_pie(%f, %f, %r);' % (r, r + perc, color));
+ r += perc;
+
+
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index de4517c..43b59cc 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -155,7 +155,9 @@ def handler(req, profiling = True):
response_code = apache.OK
try:
- read_get_vars(req)
+ # Do not parse variables again if profiling (and second run is done)
+ if profiling:
+ read_get_vars(req)
# Ajax-Functions want no HTML output in case of an error but
# just a plain server result code of 500
@@ -208,6 +210,7 @@ def handler(req, profiling = True):
os.chmod(profilefile + ".py", 0755)
return apache.OK
+
# Prepare output format
output_format = html.var("output_format", "html")
html.set_output_format(output_format)
diff --git a/web/plugins/dashboard/builtin.py b/web/plugins/dashboard/builtin.py
index 5a0ad1c..613a9c5 100644
--- a/web/plugins/dashboard/builtin.py
+++ b/web/plugins/dashboard/builtin.py
@@ -29,15 +29,40 @@ builtin_dashboards = {
"title" : _("Main Overview"),
"dashlets" : [
{
+ "url" : "dashlet_overview.py",
+ "position" : (1, 1),
+ "size" : (10, 5),
+ "shadow" : False,
+ "background" : False,
+ },
+ {
+ "title" : _("Host Statistics"),
+ "url" : "dashlet_hoststats.py",
+ "position" : (11, 1),
+ "size" : (10, 6),
+ "shadow" : True,
+ "background" : True,
+ "refresh" : 60,
+ },
+ {
+ "title" : _("Service Statistics"),
+ "url" : "dashlet_servicestats.py",
+ "position" : (21, 1),
+ "size" : (10, 6),
+ "shadow" : True,
+ "background" : True,
+ "refresh" : 60,
+ },
+ {
"title" : _("Host Problems"),
"iframe" :
"view.py?view_name=hostproblems_dash&display_options=SIXHR&_body_class=dashlet",
"position" : (-1, 1),
- "size" : (GROW, 8),
+ "size" : (GROW, 6),
},
{
"title" : _("Service Problems"),
"iframe" :
"view.py?view_name=svcproblems_dash&display_options=SIXHR&_body_class=dashlet",
- "position" : (1, 4),
+ "position" : (1, 7),
"size" : (GROW, MAX),
},
{
@@ -46,14 +71,6 @@ builtin_dashboards = {
"position" : (-1, -1),
"size" : (GROW, GROW),
},
- {
- "url" : "dashlet_overview.py",
- "position" : (1, 1),
- "size" : (GROW, 3),
- "shadow" : False,
- "background" : False,
- },
-
# {
# "title" : "CPU load of Nagios",
# # "url" :
"http://localhost/dk/pnp4nagios/index.php/image?host=DerNagiosSelbst&srv=fs__var&view=0",
diff --git a/web/plugins/pages/shipped.py b/web/plugins/pages/shipped.py
index 06c3683..b865dd4 100644
--- a/web/plugins/pages/shipped.py
+++ b/web/plugins/pages/shipped.py
@@ -63,5 +63,7 @@ pagehandlers.update({
"dashboard" : dashboard.page_dashboard,
"dashboard_resize" : dashboard.ajax_resize,
"dashlet_overview" : dashboard.dashlet_overview,
+ "dashlet_hoststats" : dashboard.dashlet_hoststats,
+ "dashlet_servicestats" : dashboard.dashlet_servicestats,
})
diff --git a/web/plugins/views/dashboard.py b/web/plugins/views/dashboard.py
index c6580f1..ccc9bb9 100644
--- a/web/plugins/views/dashboard.py
+++ b/web/plugins/views/dashboard.py
@@ -62,15 +62,15 @@ multisite_builtin_views.update({
('host_icons', None),
('host_plugin_output', None),
('host_state_age', None),
- ('host_check_age', None),
- ('num_services_ok', 'host_ok'),
+ # ('host_check_age', None), # save space
+ # ('num_services_ok', 'host_ok'), # save
space
('num_services_warn', 'host_warn'),
('num_services_crit', 'host_crit'),
('num_services_unknown', 'host_unknown'),
('num_services_pending',
'host_pending')],
'public': True,
'show_filters': [],
- 'sorters': [],
+ 'sorters': [('hoststate', True)],
'title': 'Host problems',
'topic': None,
},