mysql-connector: aggregate values by time interval on server side
This commit is contained in:
2
dist/datasource-zabbix/datasource.js
vendored
2
dist/datasource-zabbix/datasource.js
vendored
@@ -357,7 +357,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
} else {
|
||||
// Use history
|
||||
if (_this2.enableDirectDBConnection) {
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo, options.intervalMs).then(function (history) {
|
||||
return _this2.zabbix.dbConnector.handleHistory(history, items);
|
||||
});
|
||||
} else {
|
||||
|
||||
2
dist/datasource-zabbix/datasource.js.map
vendored
2
dist/datasource-zabbix/datasource.js.map
vendored
File diff suppressed because one or more lines are too long
7
dist/datasource-zabbix/zabbixDBConnector.js
vendored
7
dist/datasource-zabbix/zabbixDBConnector.js
vendored
@@ -43,16 +43,19 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
}
|
||||
}, {
|
||||
key: 'getHistory',
|
||||
value: function getHistory(items, timeFrom, timeTill) {
|
||||
value: function getHistory(items, timeFrom, timeTill, intervalMs) {
|
||||
var _this = this;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
var aggFunction = 'AVG';
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _.groupBy(items, 'value_type');
|
||||
var promises = _.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _.map(items, 'itemid').join(', ');
|
||||
var table = HISTORY_TO_TABLE_MAP[value_type];
|
||||
|
||||
var query = '\n SELECT itemid AS metric, clock AS time_sec, value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n ';
|
||||
var query = '\n SELECT itemid AS metric, clock AS time_sec, ' + aggFunction + '(value) as value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY time_sec DIV ' + intervalSec + ', metric\n ';
|
||||
|
||||
return _this.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
dist/test/datasource-zabbix/datasource.js
vendored
2
dist/test/datasource-zabbix/datasource.js
vendored
@@ -230,7 +230,7 @@ var ZabbixAPIDatasource = function () {
|
||||
} else {
|
||||
// Use history
|
||||
if (_this2.enableDirectDBConnection) {
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo, options.intervalMs).then(function (history) {
|
||||
return _this2.zabbix.dbConnector.handleHistory(history, items);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -55,16 +55,19 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
}
|
||||
}, {
|
||||
key: 'getHistory',
|
||||
value: function getHistory(items, timeFrom, timeTill) {
|
||||
value: function getHistory(items, timeFrom, timeTill, intervalMs) {
|
||||
var _this = this;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
var aggFunction = 'AVG';
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _lodash2.default.groupBy(items, 'value_type');
|
||||
var promises = _lodash2.default.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _lodash2.default.map(items, 'itemid').join(', ');
|
||||
var table = HISTORY_TO_TABLE_MAP[value_type];
|
||||
|
||||
var query = '\n SELECT itemid AS metric, clock AS time_sec, value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n ';
|
||||
var query = '\n SELECT itemid AS metric, clock AS time_sec, ' + aggFunction + '(value) as value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY time_sec DIV ' + intervalSec + ', metric\n ';
|
||||
|
||||
return _this.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user