diff --git a/src/datasource-zabbix/dataProcessor.js b/src/datasource-zabbix/dataProcessor.js index 9c3e1d1..5c66794 100644 --- a/src/datasource-zabbix/dataProcessor.js +++ b/src/datasource-zabbix/dataProcessor.js @@ -130,6 +130,18 @@ function limit(order, n, orderByFunc, timeseries) { } } +function SUM(values) { + var sum = 0; + _.each(values, function(value) { + sum += value; + }); + return sum; +} + +function COUNT(values) { + return values.length; +} + function AVERAGE(values) { var sum = 0; _.each(values, function(value) { @@ -289,6 +301,8 @@ let metricFunctions = { min: _.partial(aggregateWrapper, MIN), max: _.partial(aggregateWrapper, MAX), median: _.partial(aggregateWrapper, MEDIAN), + sum: _.partial(aggregateWrapper, SUM), + count: _.partial(aggregateWrapper, COUNT), sumSeries: sumSeries, top: _.partial(limit, 'top'), bottom: _.partial(limit, 'bottom'), @@ -301,7 +315,9 @@ let aggregationFunctions = { avg: AVERAGE, min: MIN, max: MAX, - median: MEDIAN + median: MEDIAN, + sum: SUM, + count: COUNT }; export default { @@ -311,6 +327,8 @@ export default { MIN: MIN, MAX: MAX, MEDIAN: MEDIAN, + SUM: SUM, + COUNT: COUNT, unShiftTimeSeries: unShiftTimeSeries, get aggregationFunctions() { @@ -320,4 +338,4 @@ export default { get metricFunctions() { return metricFunctions; } -}; +}; \ No newline at end of file diff --git a/src/datasource-zabbix/metricFunctions.js b/src/datasource-zabbix/metricFunctions.js index d2cca3d..c04cb6c 100644 --- a/src/datasource-zabbix/metricFunctions.js +++ b/src/datasource-zabbix/metricFunctions.js @@ -29,7 +29,7 @@ addFuncDef({ category: 'Transform', params: [ { name: 'interval', type: 'string'}, - { name: 'function', type: 'string', options: ['avg', 'min', 'max', 'median'] } + { name: 'function', type: 'string', options: ['avg', 'min', 'max', 'sum', 'count', 'median'] } ], defaultParams: ['1m', 'avg'], }); @@ -95,12 +95,30 @@ addFuncDef({ defaultParams: ['1m'], }); +addFuncDef({ + name: 'sum', + category: 'Aggregate', + params: [ + { name: 'interval', type: 'string' } + ], + defaultParams: ['1m'], +}); + +addFuncDef({ + name: 'count', + category: 'Aggregate', + params: [ + { name: 'interval', type: 'string' } + ], + defaultParams: ['1m'], +}); + addFuncDef({ name: 'aggregateBy', category: 'Aggregate', params: [ { name: 'interval', type: 'string' }, - { name: 'function', type: 'string', options: ['avg', 'min', 'max', 'median'] } + { name: 'function', type: 'string', options: ['avg', 'min', 'max', 'sum', 'count', 'median'] } ], defaultParams: ['1m', 'avg'], }); @@ -112,7 +130,7 @@ addFuncDef({ category: 'Filter', params: [ { name: 'number', type: 'int' }, - { name: 'value', type: 'string', options: ['avg', 'min', 'max', 'median'] } + { name: 'value', type: 'string', options: ['avg', 'min', 'max', 'sum', 'count', 'median'] } ], defaultParams: [5, 'avg'], }); @@ -122,7 +140,7 @@ addFuncDef({ category: 'Filter', params: [ { name: 'number', type: 'int' }, - { name: 'value', type: 'string', options: ['avg', 'min', 'max', 'median'] } + { name: 'value', type: 'string', options: ['avg', 'min', 'max', 'sum', 'count', 'median'] } ], defaultParams: [5, 'avg'], }); @@ -133,7 +151,7 @@ addFuncDef({ name: 'trendValue', category: 'Trends', params: [ - { name: 'type', type: 'string', options: ['avg', 'min', 'max'] } + { name: 'type', type: 'string', options: ['avg', 'min', 'max', 'sum', 'count'] } ], defaultParams: ['avg'], }); diff --git a/src/datasource-zabbix/query.controller.js b/src/datasource-zabbix/query.controller.js index 496a833..bc9dedb 100644 --- a/src/datasource-zabbix/query.controller.js +++ b/src/datasource-zabbix/query.controller.js @@ -79,7 +79,9 @@ export class ZabbixQueryController extends QueryCtrl { this.downsampleFunctionList = [ {name: "avg", value: "avg"}, {name: "min", value: "min"}, - {name: "max", value: "max"} + {name: "max", value: "max"}, + {name: "sum", value: "sum"}, + {name: "count", value: "count"} ]; this.initFilters(); diff --git a/src/datasource-zabbix/responseHandler.js b/src/datasource-zabbix/responseHandler.js index 13b1a2e..9060cfc 100644 --- a/src/datasource-zabbix/responseHandler.js +++ b/src/datasource-zabbix/responseHandler.js @@ -88,6 +88,12 @@ function convertTrendPoint(valueType, point) { case "avg": value = point.value_avg; break; + case "sum": + value = point.value_sum; + break; + case "count": + value = point.value_count; + break; default: value = point.value_avg; }