2013-12-25 23:21:51 +01:00
|
|
|
define([
|
|
|
|
|
'underscore'
|
|
|
|
|
],
|
|
|
|
|
function (_) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var index = [];
|
2013-12-27 23:05:51 +01:00
|
|
|
var categories = {
|
|
|
|
|
Combine: [],
|
|
|
|
|
Transform: [],
|
|
|
|
|
Calculate: [],
|
|
|
|
|
Filter: [],
|
|
|
|
|
Special: []
|
|
|
|
|
};
|
2013-12-25 23:21:51 +01:00
|
|
|
|
|
|
|
|
function addFuncDef(funcDef) {
|
2014-01-05 10:17:53 +01:00
|
|
|
funcDef.params = funcDef.params || [];
|
|
|
|
|
funcDef.defaultParams = funcDef.defaultParams || [];
|
|
|
|
|
|
2013-12-27 23:05:51 +01:00
|
|
|
if (funcDef.category) {
|
|
|
|
|
funcDef.category.push(funcDef);
|
|
|
|
|
}
|
2013-12-25 23:21:51 +01:00
|
|
|
index[funcDef.name] = funcDef;
|
|
|
|
|
index[funcDef.shortName || funcDef.name] = funcDef;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'scaleToSeconds',
|
2013-12-27 23:05:51 +01:00
|
|
|
category: categories.Transform,
|
2013-12-25 23:21:51 +01:00
|
|
|
params: [ { name: 'seconds', type: 'int' } ],
|
|
|
|
|
defaultParams: [1],
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-27 23:05:51 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: "holtWintersForecast",
|
|
|
|
|
category: categories.Calculate,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: "holtWintersConfidenceBands",
|
|
|
|
|
category: categories.Calculate,
|
|
|
|
|
params: [ { name: "delta", type: 'int' } ],
|
|
|
|
|
defaultParams: [3]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: "holtWintersAberration",
|
|
|
|
|
category: categories.Calculate,
|
|
|
|
|
params: [ { name: "delta", type: 'int' } ],
|
|
|
|
|
defaultParams: [3]
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-11 12:06:30 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: "nPercentile",
|
|
|
|
|
category: categories.Calculate,
|
|
|
|
|
params: [ { name: "Nth percentile", type: 'int' } ],
|
|
|
|
|
defaultParams: [95]
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-25 23:21:51 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'sumSeries',
|
|
|
|
|
shortName: 'sum',
|
2013-12-27 23:05:51 +01:00
|
|
|
category: categories.Combine,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'averageSeries',
|
|
|
|
|
shortName: 'avg',
|
|
|
|
|
category: categories.Combine,
|
2013-12-25 23:21:51 +01:00
|
|
|
});
|
|
|
|
|
|
2014-03-10 17:02:23 +04:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'percentileOfSeries',
|
|
|
|
|
category: categories.Combine,
|
|
|
|
|
params: [ { name: "n", type: "int" }, { name: "interpolate", type: "select", options: ["true", "false"] } ],
|
|
|
|
|
defaultParams: [95, "false"]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'sumSeriesWithWildcards',
|
|
|
|
|
category: categories.Combine,
|
|
|
|
|
params: [ { name: "node", type: "int" } ],
|
|
|
|
|
defaultParams: [3]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'averageSeriesWithWildcards',
|
|
|
|
|
category: categories.Combine,
|
|
|
|
|
params: [ { name: "node", type: "int" } ],
|
|
|
|
|
defaultParams: [3]
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-20 14:31:00 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: "alias",
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
params: [ { name: "alias", type: 'string' } ],
|
|
|
|
|
defaultParams: ['alias']
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: "aliasSub",
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
params: [ { name: "search", type: 'string' }, { name: "replace", type: 'string' } ],
|
|
|
|
|
defaultParams: ['', '']
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-25 12:21:56 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: "stacked",
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
params: [ { name: "stack", type: 'string' } ],
|
|
|
|
|
defaultParams: ['stacked']
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-25 23:21:51 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: "groupByNode",
|
2013-12-27 23:05:51 +01:00
|
|
|
category: categories.Special,
|
2013-12-25 23:21:51 +01:00
|
|
|
params: [
|
|
|
|
|
{
|
|
|
|
|
name: "node",
|
2014-03-06 22:08:41 +01:00
|
|
|
type: "int",
|
2014-01-14 21:01:41 +01:00
|
|
|
options: [1,2,3,4,5,6,7,8,9,10,12]
|
2013-12-25 23:21:51 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "function",
|
2014-03-06 22:08:41 +01:00
|
|
|
type: "string",
|
2014-01-14 21:01:41 +01:00
|
|
|
options: ['sum', 'avg']
|
2013-12-25 23:21:51 +01:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
defaultParams: [3, "sum"]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'aliasByNode',
|
2013-12-27 23:05:51 +01:00
|
|
|
category: categories.Special,
|
2014-03-06 22:08:41 +01:00
|
|
|
params: [ { name: "node", type: "int", options: [0,1,2,3,4,5,6,7,8,9,10,12] } ],
|
2013-12-25 23:21:51 +01:00
|
|
|
defaultParams: [3]
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-05 13:23:14 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'sortByName',
|
|
|
|
|
category: categories.Special
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-20 14:31:00 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'aliasByMetric',
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'randomWalk',
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
params: [ { name: "name", type: "string", } ],
|
|
|
|
|
defaultParams: ['randomWalk']
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'countSeries',
|
|
|
|
|
category: categories.Special
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'constantLine',
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
params: [ { name: "value", type: "int", } ],
|
|
|
|
|
defaultParams: [10]
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-07 15:17:39 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'cactiStyle',
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-11 12:06:30 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'keepLastValue',
|
|
|
|
|
category: categories.Special,
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-27 23:05:51 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'scale',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
params: [ { name: "factor", type: "int", } ],
|
|
|
|
|
defaultParams: [1]
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-07 15:17:39 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'offset',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
params: [ { name: "amount", type: "int", } ],
|
|
|
|
|
defaultParams: [10]
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-27 23:05:51 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'integral',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
2014-01-27 02:00:04 +01:00
|
|
|
name: 'derivative',
|
2013-12-27 23:05:51 +01:00
|
|
|
category: categories.Transform,
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-02 23:16:53 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'nonNegativeDerivative',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
params: [ { name: "max value or 0", type: "int", } ],
|
|
|
|
|
defaultParams: [0]
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-27 23:05:51 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'timeShift',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
params: [ { name: "amount", type: "select", options: ['1h', '6h', '12h', '1d', '2d', '7d', '14d', '30d'] }],
|
|
|
|
|
defaultParams: ['1d']
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-08 07:42:17 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'summarize',
|
|
|
|
|
category: categories.Transform,
|
2014-02-10 17:35:34 -06:00
|
|
|
params: [ { name: "interval", type: "string" }, { name: "func", type: "select", options: ['sum', 'avg', 'min', 'max', 'last'] }],
|
|
|
|
|
defaultParams: ['1h', 'sum']
|
2014-01-08 07:42:17 +01:00
|
|
|
});
|
|
|
|
|
|
2014-01-20 14:31:00 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'absolute',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-11 18:43:55 +00:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'hitcount',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
params: [ { name: "interval", type: "string" }],
|
|
|
|
|
defaultParams: ['10s']
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-18 19:36:31 +00:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'log',
|
|
|
|
|
category: categories.Transform,
|
|
|
|
|
params: [ { name: "base", type: "int" }],
|
|
|
|
|
defaultParams: ['10']
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2014-01-20 14:31:00 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'averageAbove',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "n", type: "int", } ],
|
|
|
|
|
defaultParams: [25]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'averageBelow',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "n", type: "int", } ],
|
|
|
|
|
defaultParams: [25]
|
|
|
|
|
});
|
|
|
|
|
|
2014-03-04 09:40:15 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'currentAbove',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "n", type: "int", } ],
|
|
|
|
|
defaultParams: [25]
|
2014-03-06 22:08:41 +01:00
|
|
|
});
|
2014-03-04 09:40:15 +01:00
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'currentBelow',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "n", type: "int", } ],
|
|
|
|
|
defaultParams: [25]
|
2014-03-06 22:08:41 +01:00
|
|
|
});
|
2014-03-04 09:40:15 +01:00
|
|
|
|
2014-02-24 10:01:58 +02:00
|
|
|
addFuncDef({
|
|
|
|
|
name: "exclude",
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "exclude", type: 'string' } ],
|
|
|
|
|
defaultParams: ['exclude']
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-05 16:10:09 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'highestCurrent',
|
|
|
|
|
category: categories.Filter,
|
2014-03-04 09:40:15 +01:00
|
|
|
params: [ { name: "count", type: "int" } ],
|
|
|
|
|
defaultParams: [5]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'highestMax',
|
|
|
|
|
category: categories.Filter,
|
2014-02-05 16:10:09 +01:00
|
|
|
params: [ { name: "count", type: "int" } ],
|
|
|
|
|
defaultParams: [5]
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-25 12:21:56 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'lowestCurrent',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "count", type: "int" } ],
|
2014-03-04 18:50:38 +01:00
|
|
|
defaultParams: [5]
|
|
|
|
|
});
|
2014-02-25 12:21:56 +01:00
|
|
|
|
2014-02-21 21:37:23 +04:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'movingAverage',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "window size", type: "int" } ],
|
|
|
|
|
defaultParams: [10]
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-26 12:37:16 +01:00
|
|
|
addFuncDef({
|
|
|
|
|
name: 'highestAverage',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "count", type: "int" } ],
|
|
|
|
|
defaultParams: [5]
|
2014-03-04 18:50:38 +01:00
|
|
|
});
|
2014-02-26 12:37:16 +01:00
|
|
|
|
|
|
|
|
addFuncDef({
|
|
|
|
|
name: 'lowestAverage',
|
|
|
|
|
category: categories.Filter,
|
|
|
|
|
params: [ { name: "count", type: "int" } ],
|
|
|
|
|
defaultParams: [5]
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-28 11:40:58 +01:00
|
|
|
_.each(categories, function(funcList, catName) {
|
|
|
|
|
categories[catName] = _.sortBy(funcList, 'name');
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-25 23:21:51 +01:00
|
|
|
function FuncInstance(funcDef) {
|
|
|
|
|
this.def = funcDef;
|
|
|
|
|
this.params = funcDef.defaultParams.slice(0);
|
|
|
|
|
this.updateText();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-06 22:08:41 +01:00
|
|
|
FuncInstance.prototype.render = function(metricExp) {
|
2014-01-20 14:31:00 +01:00
|
|
|
var str = this.def.name + '(';
|
|
|
|
|
var parameters = _.map(this.params, function(value) {
|
|
|
|
|
return _.isString(value) ? "'" + value + "'" : value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (metricExp !== undefined) {
|
|
|
|
|
parameters.unshift(metricExp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str + parameters.join(',') + ')';
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-06 22:08:41 +01:00
|
|
|
FuncInstance.prototype.updateParam = function(strValue, index) {
|
|
|
|
|
if (this.def.params[index].type === 'int') {
|
|
|
|
|
this.params[index] = parseInt(strValue, 10);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this.params[index] = strValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.updateText();
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-25 23:21:51 +01:00
|
|
|
FuncInstance.prototype.updateText = function () {
|
|
|
|
|
if (this.params.length === 0) {
|
|
|
|
|
this.text = this.def.name + '()';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var text = this.def.name + '(';
|
|
|
|
|
_.each(this.def.params, function(param, index) {
|
|
|
|
|
text += this.params[index] + ', ';
|
|
|
|
|
}, this);
|
|
|
|
|
text = text.substring(0, text.length - 2);
|
|
|
|
|
text += ')';
|
|
|
|
|
this.text = text;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
2014-01-05 10:17:53 +01:00
|
|
|
createFuncInstance: function(funcDef) {
|
|
|
|
|
if (_.isString(funcDef)) {
|
|
|
|
|
if (!index[funcDef]) {
|
2013-12-25 23:21:51 +01:00
|
|
|
throw { message: 'Method not found ' + name };
|
|
|
|
|
}
|
2014-01-05 10:17:53 +01:00
|
|
|
funcDef = index[funcDef];
|
2013-12-25 23:21:51 +01:00
|
|
|
}
|
2014-01-05 10:17:53 +01:00
|
|
|
return new FuncInstance(funcDef);
|
2013-12-25 23:21:51 +01:00
|
|
|
},
|
|
|
|
|
|
2014-03-04 18:50:38 +01:00
|
|
|
getFuncDef: function(name) {
|
|
|
|
|
return index[name];
|
|
|
|
|
},
|
|
|
|
|
|
2013-12-27 23:05:51 +01:00
|
|
|
getCategories: function() {
|
|
|
|
|
return categories;
|
2013-12-25 23:21:51 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-01-27 02:00:04 +01:00
|
|
|
});
|