Skip to content

Commit a6d2acc

Browse files
authored
Merge pull request #55 from NETWAYS/optimizations
Optimizations
2 parents 920b4c2 + 05c9dff commit a6d2acc

File tree

3 files changed

+31
-60
lines changed

3 files changed

+31
-60
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ Configuration options are limited by design.
3636

3737
Documentation for this module is available at [doc](doc/).
3838

39+
## Known Issues
40+
41+
### Timeout or page performance degeration when rendering many charts
42+
43+
When there are many performance data timeseries for a singe check command,
44+
and the selected time range is very long, fetching the data might timeout.
45+
46+
Use `perfdatagraphs_config_metrics_exlude` and `perfdatagraphs_config_metrics_include`
47+
to reduce the amout of data being loaded.
48+
3949
# Road to Version 1.0.0
4050

4151
What our current idea for a version 1.0.0 of this module is:

doc/70-Troubleshooting.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ level = "DEBUG"
1010
file = "/usr/share/icingaweb2/log/icingaweb2.log"
1111
```
1212

13-
To investigate the data returned by the backend, you can view the Hook's response by
14-
opening your Browser's development console and examine the request made by this module:
15-
16-
```
17-
http://icingaweb/perfdatagraphs/fetch?host=localhost&service=hostalive&checkcommand=hostalive&duration=PT12H
18-
```
19-
2013
To investigate the data processing and chart rendering in JavaScript
2114
open your Browser's development console and set the Icinga Web Logger to `debug` level, to see the JavaScript logs:
2215

public/js/module.js

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
const CHART_LEGEND_FORMAT = new Intl.DateTimeFormat(undefined, {dateStyle: 'short', timeStyle: 'medium'}).format;
1212

1313
class Perfdatagraphs extends Icinga.EventListener {
14-
// data contains the fetched chart data with the element ID where it is rendered as key.
15-
// Where we store data in between the autorefresh.
16-
data = new Map();
1714
// plots contains the chart objects with the element ID where it is rendered as key.
1815
// Used for resizing the charts.
1916
plots = new Map();
@@ -30,10 +27,10 @@
3027
// when their respective .container changes size.
3128
this.resizeObserver = new ResizeObserver(entries => {
3229
for (let elem of entries) {
33-
const _plots = this.plots.get(elem.target) ?? [];
34-
const s = this.getChartSize(elem.contentRect.width);
35-
for (let u of _plots) {
36-
u.setSize(s);
30+
const plot = this.plots.get(elem.target);
31+
if (plot !== undefined) {
32+
const s = this.getChartSize(elem.contentRect.width);
33+
plot.setSize(s);
3734
}
3835
}
3936
});
@@ -50,44 +47,32 @@
5047
let _this = event.data.self;
5148

5249
if (!isAutorefresh) {
50+
_this.icinga.logger.debug('perfdatagraphs', 'not an autorefresh. resetting');
5351
// Reset the selection and set the duration when it's
5452
// an autorefresh and new data is being loaded.
5553
// _this.currentSelect = {min: 0, max: 0};
5654
_this.currentSelect = null;
5755
// 1: value, 2: warning, 3: critical
5856
_this.currentSeriesShow = {};
5957
_this.currentCursor = null;
60-
_this.data = new Map();
6158
}
6259

63-
// Now we fetch
64-
_this.fetchData();
65-
// ...and render in case we already have data
66-
_this.renderCharts();
67-
}
68-
69-
/**
70-
* fetchData tries to get the data for the given object from the Controller.
71-
*/
72-
fetchData()
73-
{
74-
var _this = this;
60+
// Remove leftover eventhandlers and uPlot instances
61+
_this.plots.forEach((plot, element) => {
62+
plot.destroy();
63+
});
64+
// Then, reset the existing plots map for the new rendering
65+
_this.plots = new Map();
7566

7667
// Get the elements we going to render the charts in
7768
const lineCharts = document.querySelectorAll(CHART_CLASS);
69+
7870
// Check if the elements exist, just to be safe
7971
if (lineCharts.length < 1) {
8072
return;
8173
}
8274

83-
_this.icinga.logger.debug('perfdatagraphs', 'start fetchData', lineCharts);
84-
85-
for (let elem of lineCharts) {
86-
const perfdata = JSON.parse(elem.getAttribute('data-perfdata'));
87-
88-
_this.data.set(elem.getAttribute('id'), perfdata);
89-
_this.renderCharts();
90-
}
75+
_this.renderCharts(lineCharts);
9176
}
9277

9378
/**
@@ -228,7 +213,7 @@
228213
/**
229214
* renderCharts creates the canvas objects given the provided datasets.
230215
*/
231-
renderCharts()
216+
renderCharts(lineCharts)
232217
{
233218
// Get the colors from these sneaky little HTML elements
234219
const axesColor = $('div.axes-color').css('background-color');
@@ -238,25 +223,12 @@
238223
// These are the shared options for all charts
239224
const baseOpts = this.getChartBaseOptions();
240225

241-
// Remove leftover eventhandlers and uPlot instances
242-
this.plots.forEach((plots, element, map) => {
243-
plots.forEach((plot) => {
244-
plot.destroy();
245-
});
246-
});
247-
248-
// Reset the existing plots map for the new rendering
249-
this.plots = new Map();
226+
this.icinga.logger.debug('perfdatagraphs', 'start renderCharts');
250227

251-
this.icinga.logger.debug('perfdatagraphs', 'start renderCharts', this.data);
228+
for (let elem of lineCharts) {
229+
this.icinga.logger.debug('perfdatagraphs', 'rendering for', elem);
252230

253-
this.data.forEach((dataset, elemID, map) => {
254-
// Get the element in which we render the chart
255-
const elem = document.getElementById(elemID);
256-
257-
if (elem === null) {
258-
return;
259-
}
231+
const dataset = JSON.parse(elem.getAttribute('data-perfdata'));
260232

261233
// The size can vary from chart to chart for example when
262234
// there are two contains on the page.
@@ -355,14 +327,10 @@
355327
}
356328

357329
// Add the chart to the map which we use for the resize observer
358-
const _plots = this.plots.get(elem) || [];
359-
360-
_plots.push(u)
361-
362-
this.plots.set(elem, _plots);
363-
});
330+
this.plots.set(elem, u);
331+
}
364332

365-
this.icinga.logger.debug('perfdatagraphs', 'finish renderCharts', this.plots);
333+
this.icinga.logger.debug('perfdatagraphs', 'finish renderCharts');
366334
}
367335

368336
/**

0 commit comments

Comments
 (0)