Module: check_mk
Branch: master
Commit: e860032acb15b8a8159da4601842467eddb06a8e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e860032acb15b8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Dec 2 15:50:33 2014 +0100
#1585 FIX Dashboard: Fixed mass client CPU load consumption when making graph dashlets too
small
When PNP graph dashlets were too small, the PNP graph resizing code could get into
a situation where continous HTTP requests were made to get a smaller PNP graph where
it was not possible to get a smaller one. This resulted in a lot of CPU load by the
browser on the client host.
---
.bugs/2230 | 7 +++++--
.werks/1585 | 12 ++++++++++++
ChangeLog | 1 +
web/plugins/dashboard/dashlets.py | 22 ++++++++++++++++++++++
4 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/.bugs/2230 b/.bugs/2230
index 8e1be6f..2751767 100644
--- a/.bugs/2230
+++ b/.bugs/2230
@@ -1,9 +1,9 @@
Title: Dashboard javascript goes to 100% CPU if PNP graph cannot be rendered
Component: multisite
-State: open
+Class: bug
+State: done
Date: 2014-12-01 08:10:12
Targetversion: 1.2.5i1
-Class: bug
This happened with the following dashboard in a case where the rightmost
PNP graph was not displayabe because the size of the screen was too
@@ -358,3 +358,6 @@ small:
'single_infos': [],
'title': u'Main Graph View',
'topic': u'Overview'}}
+
+2014-12-02 15:47:35: changed state open -> done
+Fixed.
diff --git a/.werks/1585 b/.werks/1585
new file mode 100644
index 0000000..99881a6
--- /dev/null
+++ b/.werks/1585
@@ -0,0 +1,12 @@
+Title: Dashboard: Fixed mass client CPU load consumption when making graph dashlets too
small
+Level: 1
+Component: multisite
+Compatible: compat
+Version: 1.2.5i7
+Date: 1417531745
+Class: fix
+
+When PNP graph dashlets were too small, the PNP graph resizing code could get into
+a situation where continous HTTP requests were made to get a smaller PNP graph where
+it was not possible to get a smaller one. This resulted in a lot of CPU load by the
+browser on the client host.
diff --git a/ChangeLog b/ChangeLog
index ba88009..682974f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -94,6 +94,7 @@
* 1578 FIX: Folding states of containers with umlauts in titles are now persisted...
* 1580 FIX: Views: Hardcoded single context filters are not shown in filter form
anymore...
* 1581 FIX: Single context views with missing context show an error message now...
+ * 1585 FIX: Dashboard: Fixed mass client CPU load consumption when making graph
dashlets too small...
WATO:
* 1170 Added buttons to move rules to top/bottom of the list to ruleset edit dialog
diff --git a/web/plugins/dashboard/dashlets.py b/web/plugins/dashboard/dashlets.py
index 5ed326b..7e8e03c 100644
--- a/web/plugins/dashboard/dashlets.py
+++ b/web/plugins/dashboard/dashlets.py
@@ -385,6 +385,7 @@ dashlet_types["pnpgraph"] = {
var dashlet_offsets = {};
function dashboard_render_pnpgraph(nr, img_url)
{
+ // Get the target size for the graph from the inner dashlet container
var inner = document.getElementById('dashlet_inner_' + nr);
var c_w = inner.clientWidth;
var c_h = inner.clientHeight;
@@ -397,6 +398,12 @@ function dashboard_render_pnpgraph(nr, img_url)
container.appendChild(img);
}
+ // This handler is called after loading the configured graph image to verify
+ // it fits into the inner dashlet container.
+ // One could think that it can simply be solved by requesting an image of the
+ // given size from PNP/rrdtool, but this is not the case. When we request an
+ // image of a specified size, this size is used for the graphing area. The
+ // resulting image has normally labels which are added to the requested size.
img.onload = function(nr, url, w, h) {
return function() {
var i_w = this.clientWidth;
@@ -410,14 +417,29 @@ function dashboard_render_pnpgraph(nr, img_url)
return; // Finished resizing
}
+ // When the target height is smaller or equal to 81 pixels, PNP
+ // returns an image which has no labels, just the graph, which has
+ // exactly the requested height. In this situation no further resizing
+ // is needed.
if (h <= 81 || h - y_diff <= 81) {
this.style.width = '100%';
this.style.height = '100%';
return;
}
+ // Save the sizing differences between the requested size and the
+ // resulting size. This is, in fact, the size of the graph labels.
+ // load_graph_img() uses these dimensions to try to get an image
+ // which really fits the requested dimensions.
if (typeof dashlet_offsets[nr] == 'undefined') {
dashlet_offsets[nr] = [x_diff, y_diff];
+ } else if (dashlet_offsets[nr][0] != x_diff || dashlet_offsets[nr][1] !=
y_diff) {
+ // was not successful in getting a correctly sized image. Seems
+ // that PNP/rrdtool was not able to render this size. Terminate
+ // and automatically scale to 100%/100%
+ this.style.width = '100%';
+ this.style.height = '100%';
+ return;
}
load_graph_img(nr, this, url, w, h);