mysql-connector: use consolidateBy in SQL queries as agg func

This commit is contained in:
Alexander Zobnin
2017-07-22 20:57:10 +03:00
parent 327aee7ef4
commit 3795ce564e
8 changed files with 48 additions and 12 deletions

View File

@@ -371,7 +371,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
} else {
// Use history
if (_this2.enableDirectDBConnection) {
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo, options.intervalMs).then(function (history) {
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo, options).then(function (history) {
return _this2.zabbix.dbConnector.handleHistory(history, items);
});
} else {

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,7 @@
System.register(['angular', 'lodash'], function (_export, _context) {
"use strict";
var angular, _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP;
var angular, _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP, consolidateByFunc;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
@@ -43,11 +43,16 @@ System.register(['angular', 'lodash'], function (_export, _context) {
}
}, {
key: 'getHistory',
value: function getHistory(items, timeFrom, timeTill, intervalMs) {
value: function getHistory(items, timeFrom, timeTill, options) {
var _this = this;
var intervalMs = options.intervalMs,
consolidateBy = options.consolidateBy;
var intervalSec = Math.ceil(intervalMs / 1000);
var aggFunction = 'AVG';
consolidateBy = consolidateBy || 'avg';
var aggFunction = consolidateByFunc[consolidateBy];
// Group items by value type and perform request for each value type
var grouped_items = _.groupBy(items, 'value_type');
@@ -160,6 +165,13 @@ System.register(['angular', 'lodash'], function (_export, _context) {
'3': 'history_uint',
'4': 'history_text'
};
consolidateByFunc = {
'avg': 'AVG',
'min': 'MIN',
'max': 'MAX',
'sum': 'SUM',
'count': 'COUNT'
};
angular.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);
}
};

File diff suppressed because one or more lines are too long