the parallel refresher now refreshes the charts de-coupled from each other, so that a slow chart/server will not slow down the rest of the charts; fixed also CORS so that the OPTIONS requests are properly cached by the browsers
Costa Tsaousis (ktsaou) committed
Apr 23, 2016 at 03:20 UTC
5406ed8539c82c51e9cde3fd9a501139099957c5
1 file changed
+55
-35
web/dashboard.js
+55
-35
@@ -212,8 +212,6 @@
212
213
last_resized: new Date().getTime(), // the timestamp of the last resize request
214
215
- crossDomainAjax: false, // enable this to request crossDomain AJAX
216
-
215
last_page_scroll: 0, // the timestamp the last time the page was scrolled
216
217
// the current profile
@@ -308,6 +306,12 @@
306
}
307
};
308
309
+ NETDATA.statistics = {
310
+ refreshes_total: 0,
311
+ refreshes_active: 0,
312
+ refreshes_active_max: 0
313
+ };
314
+
315
316
// ----------------------------------------------------------------------------------------------------------------
317
// local storage options
@@ -565,7 +569,6 @@
569
570
$.ajax({
571
url: host + '/api/v1/charts',
568
- crossDomain: NETDATA.options.crossDomainAjax,
572
async: true,
573
cache: false
574
})
@@ -999,6 +1002,7 @@
1002
this.units = self.data('units') || null; // the units of the chart dimensions
1003
this.append_options = self.data('append-options') || null; // the units of the chart dimensions
1004
1005
+ this.running = false; // boolean - true when the chart is being refreshed now
1006
this.validated = false; // boolean - has the chart been validated?
1007
this.enabled = true; // boolean - is the chart enabled for refresh?
1008
this.paused = false; // boolean - is the chart paused for any reason?
@@ -1191,7 +1195,7 @@
1195
var lost = Math.max(h * 0.2, 5);
1196
h -= lost;
1197
1194
- // center the text, verically
1198
+ // center the text, vertically
1199
var paddingTop = (lost - 5) / 2;
1200
1201
// but check the width too
@@ -1271,8 +1275,8 @@
1275
if(isHidden() === true) return;
1276
1277
if(that.chart_created === true) {
1274
- // we should destroy it
1278
if(NETDATA.options.current.destroy_on_hide === true) {
1279
+ // we should destroy it
1280
init();
1281
}
1282
else {
@@ -1280,6 +1284,12 @@
1284
that.element_chart.style.display = 'none';
1285
if(that.element_legend !== null) that.element_legend.style.display = 'none';
1286
that.tm.last_hidden = new Date().getTime();
1287
+
1288
+ // de-allocate data
1289
+ // This works, but I not sure there are no corner cases somewhere
1290
+ // so it is commented - if the user has memory issues he can
1291
+ // set Destroy on Hide for all charts
1292
+ // that.data = null;
1293
}
1294
}
1295
@@ -2604,8 +2614,6 @@
2614
if(this.debug === true)
2615
this.log('updateChartWithData() called.');
2616
2607
- this._updating = false;
2608
-
2617
// this may force the chart to be re-created
2618
resizeChart();
2619
@@ -2700,8 +2708,8 @@
2708
if(NETDATA.globalPanAndZoom.isActive())
2709
this.tm.last_autorefreshed = 0;
2710
else {
2703
- if(NETDATA.options.current.parallel_refresher === true && NETDATA.options.current.concurrent_refreshes)
2704
- this.tm.last_autorefreshed = Math.round(now / this.data_update_every) * this.data_update_every;
2711
+ if(NETDATA.options.current.parallel_refresher === true && NETDATA.options.current.concurrent_refreshes === true)
2712
+ this.tm.last_autorefreshed = now - (now % this.data_update_every);
2713
else
2714
this.tm.last_autorefreshed = now;
2715
}
@@ -2763,11 +2771,16 @@
2771
if(this.debug === true)
2772
this.log('updating from ' + this.data_url);
2773
2774
+ NETDATA.statistics.refreshes_total++;
2775
+ NETDATA.statistics.refreshes_active++;
2776
+
2777
+ if(NETDATA.statistics.refreshes_active > NETDATA.statistics.refreshes_active_max)
2778
+ NETDATA.statistics.refreshes_active_max = NETDATA.statistics.refreshes_active;
2779
+
2780
this._updating = true;
2781
2782
this.xhr = $.ajax( {
2783
url: this.data_url,
2770
- crossDomain: NETDATA.options.crossDomainAjax,
2784
cache: false,
2785
async: true
2786
})
@@ -2781,6 +2794,7 @@
2794
error('data download failed for url: ' + that.data_url);
2795
})
2796
.always(function() {
2797
+ NETDATA.statistics.refreshes_active--;
2798
that._updating = false;
2799
if(typeof callback === 'function') callback();
2800
});
@@ -2837,13 +2851,20 @@
2851
}
2852
};
2853
2840
- this.isAutoRefreshed = function() {
2854
+ this.isAutoRefreshable = function() {
2855
return (this.current.autorefresh);
2856
};
2857
2858
this.canBeAutoRefreshed = function() {
2859
var now = new Date().getTime();
2860
2861
+ if(this.running === true) {
2862
+ if(this.debug === true)
2863
+ this.log('I am already running');
2864
+
2865
+ return false;
2866
+ }
2867
+
2868
if(this.enabled === false) {
2869
if(this.debug === true)
2870
this.log('I am not enabled');
@@ -2874,7 +2895,7 @@
2895
return true;
2896
}
2897
2877
- if(this.isAutoRefreshed() === true) {
2898
+ if(this.isAutoRefreshable() === true) {
2899
// allow the first update, even if the page is not visible
2900
if(this.updates_counter && this.updates_since_last_unhide && NETDATA.options.page_is_visible === false) {
2901
if(NETDATA.options.debug.focus === true || this.debug === true)
@@ -2934,8 +2955,16 @@
2955
};
2956
2957
this.autoRefresh = function(callback) {
2937
- if(this.canBeAutoRefreshed() === true) {
2938
- this.updateChart(callback);
2958
+ if(this.canBeAutoRefreshed() === true && this.running === false) {
2959
+ var state = this;
2960
+
2961
+ state.running = true;
2962
+ state.updateChart(function() {
2963
+ state.running = false;
2964
+
2965
+ if(typeof callback !== 'undefined')
2966
+ callback();
2967
+ });
2968
}
2969
else {
2970
if(typeof callback !== 'undefined')
@@ -2972,7 +3001,6 @@
3001
3002
$.ajax( {
3003
url: this.host + this.chart_url,
2975
- crossDomain: NETDATA.options.crossDomainAjax,
3004
cache: false,
3005
async: true
3006
})
@@ -3258,11 +3286,12 @@
3286
var parallel = new Array();
3287
var targets = NETDATA.options.targets;
3288
var len = targets.length;
3289
+ var state;
3290
while(len--) {
3262
- if(targets[len].isVisible() === false)
3291
+ state = targets[len];
3292
+ if(state.isVisible() === false || state.running === true)
3293
continue;
3294
3265
- var state = targets[len];
3295
if(state.library.initialized === false) {
3296
if(state.library.enabled === true) {
3297
state.library.initialize(NETDATA.chartRefresher);
@@ -3277,24 +3306,15 @@
3306
}
3307
3308
if(parallel.length > 0) {
3280
- var parallel_jobs = parallel.length;
3281
-
3309
// this will execute the jobs in parallel
3310
$(parallel).each(function() {
3284
- this.autoRefresh(function() {
3285
- parallel_jobs--;
3286
-
3287
- if(parallel_jobs === 0) {
3288
- setTimeout(NETDATA.chartRefresher,
3289
- NETDATA.chartRefresherWaitTime());
3290
- }
3291
- });
3311
+ this.autoRefresh();
3312
})
3313
}
3294
- else {
3295
- setTimeout(NETDATA.chartRefresher,
3296
- NETDATA.chartRefresherWaitTime());
3297
- }
3314
+
3315
+ // run the next refresh iteration
3316
+ setTimeout(NETDATA.chartRefresher,
3317
+ NETDATA.chartRefresherWaitTime());
3318
};
3319
3320
NETDATA.parseDom = function(callback) {
@@ -4647,7 +4667,7 @@
4667
state.easyPieChartEvent.timer = null;
4668
}
4669
4650
- if(state.isAutoRefreshed() === true && state.data !== null) {
4670
+ if(state.isAutoRefreshable() === true && state.data !== null) {
4671
NETDATA.easypiechartChartUpdate(state, state.data);
4672
}
4673
else {
@@ -4698,7 +4718,7 @@
4718
NETDATA.easypiechartChartUpdate = function(state, data) {
4719
var value, max, pcent;
4720
4701
- if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshed() === false) {
4721
+ if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshable() === false) {
4722
value = null;
4723
max = 0;
4724
pcent = 0;
@@ -4901,7 +4921,7 @@
4921
state.gaugeEvent.timer = null;
4922
}
4923
4904
- if(state.isAutoRefreshed() === true && state.data !== null) {
4924
+ if(state.isAutoRefreshable() === true && state.data !== null) {
4925
NETDATA.gaugeChartUpdate(state, state.data);
4926
}
4927
else {
@@ -4955,7 +4975,7 @@
4975
NETDATA.gaugeChartUpdate = function(state, data) {
4976
var value, min, max;
4977
4958
- if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshed() === false) {
4978
+ if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshable() === false) {
4979
value = 0;
4980
min = 0;
4981
max = 1;