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 {
|
} else {
|
||||||
// Use history
|
// Use history
|
||||||
if (_this2.enableDirectDBConnection) {
|
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);
|
return _this2.zabbix.dbConnector.handleHistory(history, items);
|
||||||
});
|
});
|
||||||
} else {
|
} 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',
|
key: 'getHistory',
|
||||||
value: function getHistory(items, timeFrom, timeTill) {
|
value: function getHistory(items, timeFrom, timeTill, intervalMs) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||||
|
var aggFunction = 'AVG';
|
||||||
|
|
||||||
// Group items by value type and perform request for each value type
|
// Group items by value type and perform request for each value type
|
||||||
var grouped_items = _.groupBy(items, 'value_type');
|
var grouped_items = _.groupBy(items, 'value_type');
|
||||||
var promises = _.map(grouped_items, function (items, value_type) {
|
var promises = _.map(grouped_items, function (items, value_type) {
|
||||||
var itemids = _.map(items, 'itemid').join(', ');
|
var itemids = _.map(items, 'itemid').join(', ');
|
||||||
var table = HISTORY_TO_TABLE_MAP[value_type];
|
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);
|
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 {
|
} else {
|
||||||
// Use history
|
// Use history
|
||||||
if (_this2.enableDirectDBConnection) {
|
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);
|
return _this2.zabbix.dbConnector.handleHistory(history, items);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -55,16 +55,19 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getHistory',
|
key: 'getHistory',
|
||||||
value: function getHistory(items, timeFrom, timeTill) {
|
value: function getHistory(items, timeFrom, timeTill, intervalMs) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||||
|
var aggFunction = 'AVG';
|
||||||
|
|
||||||
// Group items by value type and perform request for each value type
|
// Group items by value type and perform request for each value type
|
||||||
var grouped_items = _lodash2.default.groupBy(items, 'value_type');
|
var grouped_items = _lodash2.default.groupBy(items, 'value_type');
|
||||||
var promises = _lodash2.default.map(grouped_items, function (items, value_type) {
|
var promises = _lodash2.default.map(grouped_items, function (items, value_type) {
|
||||||
var itemids = _lodash2.default.map(items, 'itemid').join(', ');
|
var itemids = _lodash2.default.map(items, 'itemid').join(', ');
|
||||||
var table = HISTORY_TO_TABLE_MAP[value_type];
|
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);
|
return _this.invokeSQLQuery(query);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ class ZabbixAPIDatasource {
|
|||||||
} else {
|
} else {
|
||||||
// Use history
|
// Use history
|
||||||
if (this.enableDirectDBConnection) {
|
if (this.enableDirectDBConnection) {
|
||||||
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo)
|
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo, options.intervalMs)
|
||||||
.then(history => this.zabbix.dbConnector.handleHistory(history, items));
|
.then(history => this.zabbix.dbConnector.handleHistory(history, items));
|
||||||
} else {
|
} else {
|
||||||
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo)
|
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo)
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getHistory(items, timeFrom, timeTill) {
|
getHistory(items, timeFrom, timeTill, intervalMs) {
|
||||||
|
let intervalSec = Math.ceil(intervalMs / 1000);
|
||||||
|
let aggFunction = 'AVG';
|
||||||
|
|
||||||
// Group items by value type and perform request for each value type
|
// Group items by value type and perform request for each value type
|
||||||
let grouped_items = _.groupBy(items, 'value_type');
|
let grouped_items = _.groupBy(items, 'value_type');
|
||||||
let promises = _.map(grouped_items, (items, value_type) => {
|
let promises = _.map(grouped_items, (items, value_type) => {
|
||||||
@@ -45,10 +48,11 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
|||||||
let table = HISTORY_TO_TABLE_MAP[value_type];
|
let table = HISTORY_TO_TABLE_MAP[value_type];
|
||||||
|
|
||||||
let query = `
|
let query = `
|
||||||
SELECT itemid AS metric, clock AS time_sec, value
|
SELECT itemid AS metric, clock AS time_sec, ${aggFunction}(value) as value
|
||||||
FROM ${table}
|
FROM ${table}
|
||||||
WHERE itemid IN (${itemids})
|
WHERE itemid IN (${itemids})
|
||||||
AND clock > ${timeFrom} AND clock < ${timeTill}
|
AND clock > ${timeFrom} AND clock < ${timeTill}
|
||||||
|
GROUP BY time_sec DIV ${intervalSec}, metric
|
||||||
`;
|
`;
|
||||||
|
|
||||||
return this.invokeSQLQuery(query);
|
return this.invokeSQLQuery(query);
|
||||||
|
|||||||
Reference in New Issue
Block a user