Merge branch 'feature-aggregation' into develop
This commit is contained in:
@@ -171,15 +171,32 @@ function (angular, _, kbn) {
|
|||||||
items = _.flatten(items);
|
items = _.flatten(items);
|
||||||
|
|
||||||
// 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, options.scopedVars);
|
var alias = target.item.name === 'All' || itemnames.length > 1 ?
|
||||||
|
undefined : templateSrv.replace(target.alias, options.scopedVars);
|
||||||
|
|
||||||
|
var history;
|
||||||
if ((from < useTrendsFrom) && self.trends) {
|
if ((from < useTrendsFrom) && self.trends) {
|
||||||
return self.zabbixAPI.getTrends(items, from, to)
|
var points = target.downsampleFunction ? target.downsampleFunction.value : "avg";
|
||||||
.then(_.bind(zabbixHelperSrv.handleTrendResponse, zabbixHelperSrv, items, alias, target.scale));
|
history = self.zabbixAPI.getTrends(items, from, to)
|
||||||
|
.then(_.bind(zabbixHelperSrv.handleTrendResponse, zabbixHelperSrv, items, alias, target.scale, points));
|
||||||
} 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));
|
.then(_.bind(zabbixHelperSrv.handleHistoryResponse, zabbixHelperSrv, items, alias, target.scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return history.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 +212,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 };
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ function (angular, _) {
|
|||||||
* @param {Array} items Array of Zabbix Items
|
* @param {Array} items Array of Zabbix Items
|
||||||
* @param alias
|
* @param alias
|
||||||
* @param scale
|
* @param scale
|
||||||
|
* @param {string} points Point value to return: min, max or avg
|
||||||
* @param {Array} trends Array of Zabbix Trends
|
* @param {Array} trends Array of Zabbix Trends
|
||||||
*
|
*
|
||||||
* @return {Array} Array of timeseries in Grafana format
|
* @return {Array} Array of timeseries in Grafana format
|
||||||
@@ -80,7 +81,7 @@ function (angular, _) {
|
|||||||
* datapoints: [[<value>, <unixtime>], ...]
|
* datapoints: [[<value>, <unixtime>], ...]
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
this.handleTrendResponse = function (items, alias, scale, trends) {
|
this.handleTrendResponse = function (items, alias, scale, points, trends) {
|
||||||
|
|
||||||
// Group items and trends by itemid
|
// Group items and trends by itemid
|
||||||
var indexed_items = _.indexBy(items, 'itemid');
|
var indexed_items = _.indexBy(items, 'itemid');
|
||||||
@@ -95,7 +96,16 @@ function (angular, _) {
|
|||||||
datapoints: _.map(trends, function (p) {
|
datapoints: _.map(trends, function (p) {
|
||||||
|
|
||||||
// Value must be a number for properly work
|
// Value must be a number for properly work
|
||||||
var value = Number(p.value_avg);
|
var value;
|
||||||
|
if (points === "min") {
|
||||||
|
value = Number(p.value_min);
|
||||||
|
}
|
||||||
|
else if (points === "max") {
|
||||||
|
value = Number(p.value_max);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
value = Number(p.value_avg);
|
||||||
|
}
|
||||||
|
|
||||||
// Apply scale
|
// Apply scale
|
||||||
if (scale) {
|
if (scale) {
|
||||||
@@ -216,12 +226,13 @@ 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>], ...]
|
* @param {string} func Value to return: min, max or avg
|
||||||
|
* @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 +242,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;
|
||||||
downsampledSeries.push([value_avg, timeWindow.to]);
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|
||||||
// Shift time window
|
// Shift time window
|
||||||
timeWindow.to = timeWindow.from;
|
timeWindow.to = timeWindow.from;
|
||||||
@@ -246,6 +271,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