diff --git a/zabbix/datasource.js b/zabbix/datasource.js index d62b75b..57489d2 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -138,7 +138,17 @@ function (angular, _, kbn) { }, this); return $q.all(_.flatten(promises)).then(function (results) { - return { data: _.flatten(results) }; + var timeseries_data = _.flatten(results); + var data = _.map(timeseries_data, function (timeseries) { + + // Series downsampling + if (timeseries.datapoints.length > options.maxDataPoints) { + var ms_interval = Math.floor((to - from) / options.maxDataPoints) * 1000; + timeseries.datapoints = downsampleSeries(timeseries.datapoints, to, ms_interval); + } + return timeseries; + }); + return { data: data }; }); }; @@ -417,3 +427,45 @@ function formatAcknowledges(acknowledges) { return ''; } } + + +/** + * Downsample datapoints series + * + * @param {array} datapoints [[, ], ...] + * @param {integer} time_to Panel time to + * @param {integer} ms_interval Interval in milliseconds for grouping datapoints + * @return {array} [[, ], ...] + */ +function downsampleSeries(datapoints, time_to, ms_interval) { + var downsampledSeries = new Array(); + var timeWindow = { + from: time_to * 1000 - ms_interval, + to: time_to * 1000 + }; + + var points_sum = 0; + var points_num = 0; + var value_avg = 0; + for (var i = datapoints.length - 1; i >= 0; i -= 1) { + if (timeWindow.from < datapoints[i][1] && datapoints[i][1] <= timeWindow.to) { + points_sum += datapoints[i][0]; + points_num++; + } + else { + value_avg = points_num ? points_sum / points_num : 0; + downsampledSeries.push([value_avg, timeWindow.to]); + + // Shift time window + timeWindow.to = timeWindow.from; + timeWindow.from -= ms_interval; + + points_sum = 0; + points_num = 0; + + // Process point again + i++; + } + } + return downsampledSeries.reverse(); +} \ No newline at end of file diff --git a/zabbix/partials/query.editor.html b/zabbix/partials/query.editor.html index 44dcf66..a41f6a5 100644 --- a/zabbix/partials/query.editor.html +++ b/zabbix/partials/query.editor.html @@ -174,3 +174,59 @@ + +
+
+
    +
  • + +
  • +
  • + Max data points +
  • +
  • + +
  • +
+
+
+
+ +
+
+
+ +
+
+ +
+
Max data points
+
    +
  • Every graphite request is issued with a maxDataPoints parameter
  • +
  • Graphite uses this parameter to consolidate the real number of values down to this number
  • +
  • If there are more real values, then by default they will be consolidated using averages
  • +
  • This could hide real peaks and max values in your series
  • +
  • You can change how point consolidation is made using the consolidateBy graphite function
  • +
  • Point consolidation will effect series legend values (min,max,total,current)
  • +
  • If you override maxDataPoint and set a high value performance can be severely effected
  • +
+
+ +
+
\ No newline at end of file