Merge branch 'develop'

This commit is contained in:
Alexander Zobnin
2016-07-03 10:01:15 +03:00
6 changed files with 55 additions and 19 deletions

View File

@@ -142,6 +142,15 @@ export default class DataProcessor {
return timeseries; return timeseries;
} }
static scale(factor, datapoints) {
return _.map(datapoints, point => {
return [
point[0] * factor,
point[1]
];
});
}
static groupByWrapper(interval, groupFunc, datapoints) { static groupByWrapper(interval, groupFunc, datapoints) {
var groupByCallback = DataProcessor.aggregationFunctions[groupFunc]; var groupByCallback = DataProcessor.aggregationFunctions[groupFunc];
return DataProcessor.groupBy(interval, groupByCallback, datapoints); return DataProcessor.groupBy(interval, groupByCallback, datapoints);
@@ -171,6 +180,7 @@ export default class DataProcessor {
static get metricFunctions() { static get metricFunctions() {
return { return {
groupBy: this.groupByWrapper, groupBy: this.groupByWrapper,
scale: this.scale,
aggregateBy: this.aggregateByWrapper, aggregateBy: this.aggregateByWrapper,
average: _.partial(this.aggregateWrapper, this.AVERAGE), average: _.partial(this.aggregateWrapper, this.AVERAGE),
min: _.partial(this.aggregateWrapper, this.MIN), min: _.partial(this.aggregateWrapper, this.MIN),
@@ -223,7 +233,7 @@ function findNearestRight(series, point) {
var point_index = _.indexOf(series, point); var point_index = _.indexOf(series, point);
var nearestRight; var nearestRight;
for (var i = point_index; i < series.length; i++) { for (var i = point_index; i < series.length; i++) {
if (series[i][0]) { if (series[i][0] !== null) {
return series[i]; return series[i];
} }
} }
@@ -234,7 +244,7 @@ function findNearestLeft(series, point) {
var point_index = _.indexOf(series, point); var point_index = _.indexOf(series, point);
var nearestLeft; var nearestLeft;
for (var i = point_index; i > 0; i--) { for (var i = point_index; i > 0; i--) {
if (series[i][0]) { if (series[i][0] !== null) {
return series[i]; return series[i];
} }
} }

View File

@@ -176,10 +176,10 @@ export class ZabbixAPIDatasource {
// Apply transformation functions // Apply transformation functions
timeseries_data = _.map(timeseries_data, timeseries => { timeseries_data = _.map(timeseries_data, timeseries => {
// Filter only transform functions // Filter only transformation functions
var transformFunctions = bindFunctionDefs(target.functions, 'Transform', DataProcessor); var transformFunctions = bindFunctionDefs(target.functions, 'Transform', DataProcessor);
// Metric data processing // Timeseries processing
var dp = timeseries.datapoints; var dp = timeseries.datapoints;
for (var i = 0; i < transformFunctions.length; i++) { for (var i = 0; i < transformFunctions.length; i++) {
dp = transformFunctions[i](dp); dp = transformFunctions[i](dp);
@@ -492,7 +492,7 @@ function zabbixTemplateFormat(value, variable) {
function replaceTemplateVars(templateSrv, target, scopedVars) { function replaceTemplateVars(templateSrv, target, scopedVars) {
var replacedTarget = templateSrv.replace(target, scopedVars, zabbixTemplateFormat); var replacedTarget = templateSrv.replace(target, scopedVars, zabbixTemplateFormat);
if (target !== replacedTarget && !utils.regexPattern.test(replacedTarget)) { if (target !== replacedTarget && !utils.regexPattern.test(replacedTarget)) {
replacedTarget = '/' + replacedTarget + '/'; replacedTarget = '/^' + replacedTarget + '$/';
} }
return replacedTarget; return replacedTarget;
} }

View File

@@ -102,7 +102,8 @@ angular
$input.attr('data-provide', 'typeahead'); $input.attr('data-provide', 'typeahead');
var options = funcDef.params[paramIndex].options; 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(); }); options = _.map(options, function(val) { return val.toString(); });
} }

View File

@@ -30,6 +30,15 @@ addFuncDef({
defaultParams: ['1m', 'avg'], defaultParams: ['1m', 'avg'],
}); });
addFuncDef({
name: 'scale',
category: 'Transform',
params: [
{ name: 'factor', type: 'float', options: [100, 0.01, 10, -1]}
],
defaultParams: [100],
});
addFuncDef({ addFuncDef({
name: 'sumSeries', name: 'sumSeries',
category: 'Aggregate', category: 'Aggregate',
@@ -126,8 +135,16 @@ class FuncInstance {
// Bind function arguments // Bind function arguments
var bindedFunc = func; var bindedFunc = func;
var param;
for (var i = 0; i < this.params.length; i++) { 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; return bindedFunc;
} else { } else {
@@ -140,7 +157,10 @@ class FuncInstance {
var parameters = _.map(this.params, function(value, index) { var parameters = _.map(this.params, function(value, index) {
var paramType = this.def.params[index].type; 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; return value;
} }
else if (paramType === 'int_or_interval' && $.isNumeric(value)) { else if (paramType === 'int_or_interval' && $.isNumeric(value)) {

View File

@@ -126,6 +126,17 @@
</div> </div>
</div> </div>
<!-- Query options -->
<div class="gf-form-group" ng-if="ctrl.showQueryOptions">
<div class="gf-form offset-width-7">
<gf-form-switch class="gf-form" ng-hide="ctrl.target.mode == 2"
label="Show disabled items"
checked="ctrl.target.options.showDisabledItems"
on-change="ctrl.onQueryOptionChange()">
</gf-form-switch>
</div>
</div>
<!-- Metric processing functions --> <!-- Metric processing functions -->
<div class="gf-form-inline" ng-hide="ctrl.target.mode"> <div class="gf-form-inline" ng-hide="ctrl.target.mode">
<div class="gf-form"> <div class="gf-form">
@@ -156,15 +167,4 @@
</gf-form-switch> </gf-form-switch>
</div> </div>
<!-- Query options -->
<div class="gf-form-group" ng-if="ctrl.showQueryOptions">
<div class="gf-form offset-width-7">
<gf-form-switch class="gf-form" ng-hide="ctrl.target.mode == 2"
label="Show disabled items"
checked="ctrl.target.options.showDisabledItems"
on-change="ctrl.onQueryOptionChange()">
</gf-form-switch>
</div>
</div>
</query-editor-row> </query-editor-row>

View File

@@ -40,6 +40,11 @@ export class ZabbixQueryController extends QueryCtrl {
// Update metric suggestion when template variable was changed // Update metric suggestion when template variable was changed
$rootScope.$on('template-variable-value-updated', () => this.onVariableChange()); $rootScope.$on('template-variable-value-updated', () => this.onVariableChange());
// Update metrics when item selected from dropdown
$scope.$on('typeahead-updated', () => {
this.onTargetBlur();
});
this.init = function() { this.init = function() {
var target = this.target; var target = this.target;