mysql-connector: use consolidateBy in SQL queries as agg func
This commit is contained in:
2
dist/datasource-zabbix/datasource.js
vendored
2
dist/datasource-zabbix/datasource.js
vendored
@@ -371,7 +371,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, options.intervalMs).then(function (history) {
|
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo, options).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
18
dist/datasource-zabbix/zabbixDBConnector.js
vendored
18
dist/datasource-zabbix/zabbixDBConnector.js
vendored
@@ -3,7 +3,7 @@
|
|||||||
System.register(['angular', 'lodash'], function (_export, _context) {
|
System.register(['angular', 'lodash'], function (_export, _context) {
|
||||||
"use strict";
|
"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) {
|
function _classCallCheck(instance, Constructor) {
|
||||||
if (!(instance instanceof Constructor)) {
|
if (!(instance instanceof Constructor)) {
|
||||||
@@ -43,11 +43,16 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getHistory',
|
key: 'getHistory',
|
||||||
value: function getHistory(items, timeFrom, timeTill, intervalMs) {
|
value: function getHistory(items, timeFrom, timeTill, options) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
var intervalMs = options.intervalMs,
|
||||||
|
consolidateBy = options.consolidateBy;
|
||||||
|
|
||||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
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
|
// 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');
|
||||||
@@ -160,6 +165,13 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
|||||||
'3': 'history_uint',
|
'3': 'history_uint',
|
||||||
'4': 'history_text'
|
'4': 'history_text'
|
||||||
};
|
};
|
||||||
|
consolidateByFunc = {
|
||||||
|
'avg': 'AVG',
|
||||||
|
'min': 'MIN',
|
||||||
|
'max': 'MAX',
|
||||||
|
'sum': 'SUM',
|
||||||
|
'count': 'COUNT'
|
||||||
|
};
|
||||||
angular.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);
|
angular.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
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
@@ -231,7 +231,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
} else {
|
} else {
|
||||||
// Use history
|
// Use history
|
||||||
if (_this2.enableDirectDBConnection) {
|
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);
|
return _this2.zabbix.dbConnector.handleHistory(history, items);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
17
dist/test/datasource-zabbix/zabbixDBConnector.js
vendored
17
dist/test/datasource-zabbix/zabbixDBConnector.js
vendored
@@ -23,6 +23,14 @@ var HISTORY_TO_TABLE_MAP = {
|
|||||||
'4': 'history_text'
|
'4': 'history_text'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var consolidateByFunc = {
|
||||||
|
'avg': 'AVG',
|
||||||
|
'min': 'MIN',
|
||||||
|
'max': 'MAX',
|
||||||
|
'sum': 'SUM',
|
||||||
|
'count': 'COUNT'
|
||||||
|
};
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||||
var ZabbixDBConnector = function () {
|
var ZabbixDBConnector = function () {
|
||||||
@@ -55,11 +63,16 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getHistory',
|
key: 'getHistory',
|
||||||
value: function getHistory(items, timeFrom, timeTill, intervalMs) {
|
value: function getHistory(items, timeFrom, timeTill, options) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
var intervalMs = options.intervalMs,
|
||||||
|
consolidateBy = options.consolidateBy;
|
||||||
|
|
||||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
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
|
// 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');
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class ZabbixAPIDatasource {
|
|||||||
} else {
|
} else {
|
||||||
// Use history
|
// Use history
|
||||||
if (this.enableDirectDBConnection) {
|
if (this.enableDirectDBConnection) {
|
||||||
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo, options.intervalMs)
|
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo, options)
|
||||||
.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)
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ const HISTORY_TO_TABLE_MAP = {
|
|||||||
'4': 'history_text'
|
'4': 'history_text'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const consolidateByFunc = {
|
||||||
|
'avg': 'AVG',
|
||||||
|
'min': 'MIN',
|
||||||
|
'max': 'MAX',
|
||||||
|
'sum': 'SUM',
|
||||||
|
'count': 'COUNT'
|
||||||
|
};
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||||
|
|
||||||
@@ -37,9 +45,12 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getHistory(items, timeFrom, timeTill, intervalMs) {
|
getHistory(items, timeFrom, timeTill, options) {
|
||||||
|
let {intervalMs, consolidateBy} = options;
|
||||||
let intervalSec = Math.ceil(intervalMs / 1000);
|
let intervalSec = Math.ceil(intervalMs / 1000);
|
||||||
let aggFunction = 'AVG';
|
|
||||||
|
consolidateBy = consolidateBy || 'avg';
|
||||||
|
let aggFunction = consolidateByFunc[consolidateBy];
|
||||||
|
|
||||||
// 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');
|
||||||
|
|||||||
Reference in New Issue
Block a user