percentil: refactor
This commit is contained in:
10
dist/datasource-zabbix/dataProcessor.js
vendored
10
dist/datasource-zabbix/dataProcessor.js
vendored
@@ -3,7 +3,7 @@
|
||||
System.register(['lodash', './utils', './timeseries'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _, utils, ts, downsampleSeries, groupBy, groupBy_exported, sumSeries, delta, rate, scale, simpleMovingAverage, expMovingAverage, SUM, COUNT, AVERAGE, MIN, MAX, MEDIAN, metricFunctions, aggregationFunctions;
|
||||
var _, utils, ts, downsampleSeries, groupBy, groupBy_exported, sumSeries, delta, rate, scale, simpleMovingAverage, expMovingAverage, SUM, COUNT, AVERAGE, MIN, MAX, MEDIAN, PERCENTIL, metricFunctions, aggregationFunctions;
|
||||
|
||||
function limit(order, n, orderByFunc, timeseries) {
|
||||
var orderByCallback = aggregationFunctions[orderByFunc];
|
||||
@@ -68,6 +68,12 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
|
||||
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||
}
|
||||
|
||||
function percentil(interval, n, datapoints) {
|
||||
var flattenedPoints = _.flatten(datapoints, true);
|
||||
var groupByCallback = _.partial(PERCENTIL, n);
|
||||
return groupBy(flattenedPoints, interval, groupByCallback);
|
||||
}
|
||||
|
||||
function timeShift(interval, range) {
|
||||
var shift = utils.parseTimeShiftInterval(interval) / 1000;
|
||||
return _.map(range, function (time) {
|
||||
@@ -120,6 +126,7 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
|
||||
MIN = ts.MIN;
|
||||
MAX = ts.MAX;
|
||||
MEDIAN = ts.MEDIAN;
|
||||
PERCENTIL = ts.PERCENTIL;
|
||||
metricFunctions = {
|
||||
groupBy: groupByWrapper,
|
||||
scale: scale,
|
||||
@@ -129,6 +136,7 @@ System.register(['lodash', './utils', './timeseries'], function (_export, _conte
|
||||
exponentialMovingAverage: expMovingAverage,
|
||||
aggregateBy: aggregateByWrapper,
|
||||
// Predefined aggs
|
||||
percentil: percentil,
|
||||
average: _.partial(aggregateWrapper, AVERAGE),
|
||||
min: _.partial(aggregateWrapper, MIN),
|
||||
max: _.partial(aggregateWrapper, MAX),
|
||||
|
||||
2
dist/datasource-zabbix/dataProcessor.js.map
vendored
2
dist/datasource-zabbix/dataProcessor.js.map
vendored
File diff suppressed because one or more lines are too long
7
dist/datasource-zabbix/metricFunctions.js
vendored
7
dist/datasource-zabbix/metricFunctions.js
vendored
@@ -148,6 +148,13 @@ System.register(['lodash', 'jquery'], function (_export, _context) {
|
||||
defaultParams: ['1m']
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'percentil',
|
||||
category: 'Aggregate',
|
||||
params: [{ name: 'interval', type: 'string' }, { name: 'percent', type: 'float', options: [25, 50, 75, 90, 95, 99, 99.9] }],
|
||||
defaultParams: ['1m', 95]
|
||||
});
|
||||
|
||||
addFuncDef({
|
||||
name: 'min',
|
||||
category: 'Aggregate',
|
||||
|
||||
File diff suppressed because one or more lines are too long
8
dist/datasource-zabbix/timeseries.js
vendored
8
dist/datasource-zabbix/timeseries.js
vendored
@@ -305,6 +305,11 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
||||
return ema;
|
||||
}
|
||||
|
||||
function PERCENTIL(n, values) {
|
||||
var sorted = _.sortBy(values);
|
||||
return sorted[Math.floor(sorted.length * n / 100)];
|
||||
}
|
||||
|
||||
function COUNT(values) {
|
||||
return values.length;
|
||||
}
|
||||
@@ -474,7 +479,8 @@ System.register(['lodash', './utils'], function (_export, _context) {
|
||||
AVERAGE: AVERAGE,
|
||||
MIN: MIN,
|
||||
MAX: MAX,
|
||||
MEDIAN: MEDIAN
|
||||
MEDIAN: MEDIAN,
|
||||
PERCENTIL: PERCENTIL
|
||||
};
|
||||
|
||||
_export('default', exportedFunctions);
|
||||
|
||||
2
dist/datasource-zabbix/timeseries.js.map
vendored
2
dist/datasource-zabbix/timeseries.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user