diff --git a/src/datasource-zabbix/DataProcessor.js b/src/datasource-zabbix/DataProcessor.js index e2743bd..0dad30d 100644 --- a/src/datasource-zabbix/DataProcessor.js +++ b/src/datasource-zabbix/DataProcessor.js @@ -142,6 +142,15 @@ export default class DataProcessor { return timeseries; } + static scale(factor, datapoints) { + return _.map(datapoints, point => { + return [ + point[0] * factor, + point[1] + ]; + }); + } + static groupByWrapper(interval, groupFunc, datapoints) { var groupByCallback = DataProcessor.aggregationFunctions[groupFunc]; return DataProcessor.groupBy(interval, groupByCallback, datapoints); @@ -171,6 +180,7 @@ export default class DataProcessor { static get metricFunctions() { return { groupBy: this.groupByWrapper, + scale: this.scale, aggregateBy: this.aggregateByWrapper, average: _.partial(this.aggregateWrapper, this.AVERAGE), min: _.partial(this.aggregateWrapper, this.MIN), @@ -223,7 +233,7 @@ function findNearestRight(series, point) { var point_index = _.indexOf(series, point); var nearestRight; for (var i = point_index; i < series.length; i++) { - if (series[i][0]) { + if (series[i][0] !== null) { return series[i]; } } @@ -234,7 +244,7 @@ function findNearestLeft(series, point) { var point_index = _.indexOf(series, point); var nearestLeft; for (var i = point_index; i > 0; i--) { - if (series[i][0]) { + if (series[i][0] !== null) { return series[i]; } } diff --git a/src/datasource-zabbix/datasource.js b/src/datasource-zabbix/datasource.js index a3f1f12..2f5d792 100644 --- a/src/datasource-zabbix/datasource.js +++ b/src/datasource-zabbix/datasource.js @@ -176,10 +176,10 @@ export class ZabbixAPIDatasource { // Apply transformation functions timeseries_data = _.map(timeseries_data, timeseries => { - // Filter only transform functions + // Filter only transformation functions var transformFunctions = bindFunctionDefs(target.functions, 'Transform', DataProcessor); - // Metric data processing + // Timeseries processing var dp = timeseries.datapoints; for (var i = 0; i < transformFunctions.length; i++) { dp = transformFunctions[i](dp); @@ -492,7 +492,7 @@ function zabbixTemplateFormat(value, variable) { function replaceTemplateVars(templateSrv, target, scopedVars) { var replacedTarget = templateSrv.replace(target, scopedVars, zabbixTemplateFormat); if (target !== replacedTarget && !utils.regexPattern.test(replacedTarget)) { - replacedTarget = '/' + replacedTarget + '/'; + replacedTarget = '/^' + replacedTarget + '$/'; } return replacedTarget; } diff --git a/src/datasource-zabbix/metric-function-editor.directive.js b/src/datasource-zabbix/metric-function-editor.directive.js index e001194..8862c01 100644 --- a/src/datasource-zabbix/metric-function-editor.directive.js +++ b/src/datasource-zabbix/metric-function-editor.directive.js @@ -102,7 +102,8 @@ angular $input.attr('data-provide', 'typeahead'); var options = funcDef.params[paramIndex].options; - if (funcDef.params[paramIndex].type === 'int') { + if (funcDef.params[paramIndex].type === 'int' || + funcDef.params[paramIndex].type === 'float') { options = _.map(options, function(val) { return val.toString(); }); } diff --git a/src/datasource-zabbix/metricFunctions.js b/src/datasource-zabbix/metricFunctions.js index 024aa0d..5616bc2 100644 --- a/src/datasource-zabbix/metricFunctions.js +++ b/src/datasource-zabbix/metricFunctions.js @@ -30,6 +30,15 @@ addFuncDef({ defaultParams: ['1m', 'avg'], }); +addFuncDef({ + name: 'scale', + category: 'Transform', + params: [ + { name: 'factor', type: 'float', options: [100, 0.01, 10, -1]} + ], + defaultParams: [100], +}); + addFuncDef({ name: 'sumSeries', category: 'Aggregate', @@ -126,8 +135,16 @@ class FuncInstance { // Bind function arguments var bindedFunc = func; + var param; for (var i = 0; i < this.params.length; i++) { - bindedFunc = _.partial(bindedFunc, this.params[i]); + param = this.params[i]; + + // Convert numeric params + if (this.def.params[i].type === 'int' || + this.def.params[i].type === 'float') { + param = Number(param); + } + bindedFunc = _.partial(bindedFunc, param); } return bindedFunc; } else { @@ -140,7 +157,10 @@ class FuncInstance { var parameters = _.map(this.params, function(value, index) { var paramType = this.def.params[index].type; - if (paramType === 'int' || paramType === 'value_or_series' || paramType === 'boolean') { + if (paramType === 'int' || + paramType === 'float' || + paramType === 'value_or_series' || + paramType === 'boolean') { return value; } else if (paramType === 'int_or_interval' && $.isNumeric(value)) { diff --git a/src/datasource-zabbix/partials/query.editor.html b/src/datasource-zabbix/partials/query.editor.html index a88335e..5a7df44 100644 --- a/src/datasource-zabbix/partials/query.editor.html +++ b/src/datasource-zabbix/partials/query.editor.html @@ -126,6 +126,17 @@ + +
+
+ + +
+
+
@@ -156,15 +167,4 @@
- -
-
- - -
-
- diff --git a/src/datasource-zabbix/query.controller.js b/src/datasource-zabbix/query.controller.js index ddd23b7..ca271cc 100644 --- a/src/datasource-zabbix/query.controller.js +++ b/src/datasource-zabbix/query.controller.js @@ -40,6 +40,11 @@ export class ZabbixQueryController extends QueryCtrl { // Update metric suggestion when template variable was changed $rootScope.$on('template-variable-value-updated', () => this.onVariableChange()); + // Update metrics when item selected from dropdown + $scope.$on('typeahead-updated', () => { + this.onTargetBlur(); + }); + this.init = function() { var target = this.target;