iss #60 - Added processing functions for downsampling: min, max, avg.
This commit is contained in:
@@ -173,13 +173,31 @@ function (angular, _, kbn) {
|
|||||||
// Use alias only for single metric, otherwise use item names
|
// Use alias only for single metric, otherwise use item names
|
||||||
var alias = target.item.name === 'All' || itemnames.length > 1 ? undefined : templateSrv.replace(target.alias);
|
var alias = target.item.name === 'All' || itemnames.length > 1 ? undefined : templateSrv.replace(target.alias);
|
||||||
|
|
||||||
|
var history;
|
||||||
|
var handleFunction;
|
||||||
if ((from < useTrendsFrom) && self.trends) {
|
if ((from < useTrendsFrom) && self.trends) {
|
||||||
return self.zabbixAPI.getTrends(items, from, to)
|
history = self.zabbixAPI.getTrends(items, from, to);
|
||||||
.then(_.bind(zabbixHelperSrv.handleTrendResponse, zabbixHelperSrv, items, alias, target.scale));
|
handleFunction = zabbixHelperSrv.handleTrendResponse;
|
||||||
} else {
|
} else {
|
||||||
return self.zabbixAPI.getHistory(items, from, to)
|
history = self.zabbixAPI.getHistory(items, from, to);
|
||||||
.then(_.bind(zabbixHelperSrv.handleHistoryResponse, zabbixHelperSrv, items, alias, target.scale));
|
handleFunction = zabbixHelperSrv.handleHistoryResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return history
|
||||||
|
.then(_.bind(handleFunction, zabbixHelperSrv, items, alias, target.scale))
|
||||||
|
.then(function (timeseries) {
|
||||||
|
var timeseries_data = _.flatten(timeseries);
|
||||||
|
return _.map(timeseries_data, function (timeseries) {
|
||||||
|
|
||||||
|
// Series downsampling
|
||||||
|
if (timeseries.datapoints.length > options.maxDataPoints) {
|
||||||
|
var ms_interval = Math.floor((to - from) / options.maxDataPoints) * 1000;
|
||||||
|
var downsampleFunc = target.downsampleFunction ? target.downsampleFunction.value : "avg";
|
||||||
|
timeseries.datapoints = zabbixHelperSrv.downsampleSeries(timeseries.datapoints, to, ms_interval, downsampleFunc);
|
||||||
|
}
|
||||||
|
return timeseries;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -195,16 +213,7 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
return $q.all(_.flatten(promises)).then(function (results) {
|
return $q.all(_.flatten(promises)).then(function (results) {
|
||||||
var timeseries_data = _.flatten(results);
|
var timeseries_data = _.flatten(results);
|
||||||
var data = _.map(timeseries_data, function (timeseries) {
|
return { data: timeseries_data };
|
||||||
|
|
||||||
// Series downsampling
|
|
||||||
if (timeseries.datapoints.length > options.maxDataPoints) {
|
|
||||||
var ms_interval = Math.floor((to - from) / options.maxDataPoints) * 1000;
|
|
||||||
timeseries.datapoints = zabbixHelperSrv.downsampleSeries(timeseries.datapoints, to, ms_interval);
|
|
||||||
}
|
|
||||||
return timeseries;
|
|
||||||
});
|
|
||||||
return { data: data };
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -216,12 +216,12 @@ function (angular, _) {
|
|||||||
/**
|
/**
|
||||||
* Downsample datapoints series
|
* Downsample datapoints series
|
||||||
*
|
*
|
||||||
* @param {array} datapoints [[<value>, <unixtime>], ...]
|
* @param {Object[]} datapoints [[<value>, <unixtime>], ...]
|
||||||
* @param {integer} time_to Panel time to
|
* @param {integer} time_to Panel time to
|
||||||
* @param {integer} ms_interval Interval in milliseconds for grouping datapoints
|
* @param {integer} ms_interval Interval in milliseconds for grouping datapoints
|
||||||
* @return {array} [[<value>, <unixtime>], ...]
|
* @return {Object[]} [[<value>, <unixtime>], ...]
|
||||||
*/
|
*/
|
||||||
this.downsampleSeries = function(datapoints, time_to, ms_interval) {
|
this.downsampleSeries = function(datapoints, time_to, ms_interval, func) {
|
||||||
var downsampledSeries = [];
|
var downsampledSeries = [];
|
||||||
var timeWindow = {
|
var timeWindow = {
|
||||||
from: time_to * 1000 - ms_interval,
|
from: time_to * 1000 - ms_interval,
|
||||||
@@ -231,14 +231,28 @@ function (angular, _) {
|
|||||||
var points_sum = 0;
|
var points_sum = 0;
|
||||||
var points_num = 0;
|
var points_num = 0;
|
||||||
var value_avg = 0;
|
var value_avg = 0;
|
||||||
|
var frame = [];
|
||||||
|
|
||||||
for (var i = datapoints.length - 1; i >= 0; i -= 1) {
|
for (var i = datapoints.length - 1; i >= 0; i -= 1) {
|
||||||
if (timeWindow.from < datapoints[i][1] && datapoints[i][1] <= timeWindow.to) {
|
if (timeWindow.from < datapoints[i][1] && datapoints[i][1] <= timeWindow.to) {
|
||||||
points_sum += datapoints[i][0];
|
points_sum += datapoints[i][0];
|
||||||
points_num++;
|
points_num++;
|
||||||
|
frame.push(datapoints[i][0]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
value_avg = points_num ? points_sum / points_num : 0;
|
value_avg = points_num ? points_sum / points_num : 0;
|
||||||
|
|
||||||
|
if (func === "max") {
|
||||||
|
downsampledSeries.push([_.max(frame), timeWindow.to]);
|
||||||
|
}
|
||||||
|
else if (func === "min") {
|
||||||
|
downsampledSeries.push([_.min(frame), timeWindow.to]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// avg by default
|
||||||
|
else {
|
||||||
downsampledSeries.push([value_avg, timeWindow.to]);
|
downsampledSeries.push([value_avg, timeWindow.to]);
|
||||||
|
}
|
||||||
|
|
||||||
// Shift time window
|
// Shift time window
|
||||||
timeWindow.to = timeWindow.from;
|
timeWindow.to = timeWindow.from;
|
||||||
@@ -246,6 +260,7 @@ function (angular, _) {
|
|||||||
|
|
||||||
points_sum = 0;
|
points_sum = 0;
|
||||||
points_num = 0;
|
points_num = 0;
|
||||||
|
frame = [];
|
||||||
|
|
||||||
// Process point again
|
// Process point again
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@@ -131,6 +131,21 @@
|
|||||||
placeholder="Host filter (regex)"
|
placeholder="Host filter (regex)"
|
||||||
ng-blur="targetBlur()">
|
ng-blur="targetBlur()">
|
||||||
</li>
|
</li>
|
||||||
|
<!-- Downsampling function -->
|
||||||
|
<li class="tight-form-item input-medium">Downsampling</li>
|
||||||
|
<li>
|
||||||
|
<select class="tight-form-input input-small"
|
||||||
|
ng-change="targetBlur()"
|
||||||
|
ng-model="target.downsampleFunction"
|
||||||
|
bs-tooltip="'Downsampling function'"
|
||||||
|
ng-options="func.name for func in downsampleFunctionList track by func.name">
|
||||||
|
</select>
|
||||||
|
<a bs-tooltip="target.errors.metric"
|
||||||
|
style="color: rgb(229, 189, 28)"
|
||||||
|
ng-show="target.errors.metric">
|
||||||
|
<i class="icon-warning-sign"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
|
|||||||
@@ -24,6 +24,16 @@ define([
|
|||||||
$scope.itserviceList = [{name: "test"}];
|
$scope.itserviceList = [{name: "test"}];
|
||||||
$scope.updateITServiceList();
|
$scope.updateITServiceList();
|
||||||
} else {
|
} else {
|
||||||
|
$scope.downsampleFunctionList = [
|
||||||
|
{name: "avg", value: "avg"},
|
||||||
|
{name: "min", value: "min"},
|
||||||
|
{name: "max", value: "max"}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Set avg by default
|
||||||
|
if (!$scope.target.downsampleFunction) {
|
||||||
|
$scope.target.downsampleFunction = $scope.downsampleFunctionList[0];
|
||||||
|
}
|
||||||
$scope.metric = {
|
$scope.metric = {
|
||||||
hostGroupList: [],
|
hostGroupList: [],
|
||||||
hostList: [{name: '*', visible_name: 'All'}],
|
hostList: [{name: '*', visible_name: 'All'}],
|
||||||
|
|||||||
Reference in New Issue
Block a user