diff --git a/src/datasource-zabbix/DataProcessor.js b/src/datasource-zabbix/DataProcessor.js index c47965e..e2743bd 100644 --- a/src/datasource-zabbix/DataProcessor.js +++ b/src/datasource-zabbix/DataProcessor.js @@ -147,6 +147,13 @@ export default class DataProcessor { return DataProcessor.groupBy(interval, groupByCallback, datapoints); } + static aggregateByWrapper(interval, aggregateFunc, datapoints) { + // Flatten all points in frame and then just use groupBy() + var flattenedPoints = _.flatten(datapoints, true); + var groupByCallback = DataProcessor.aggregationFunctions[aggregateFunc]; + return DataProcessor.groupBy(interval, groupByCallback, flattenedPoints); + } + static aggregateWrapper(groupByCallback, interval, datapoints) { var flattenedPoints = _.flatten(datapoints, true); return DataProcessor.groupBy(interval, groupByCallback, flattenedPoints); @@ -164,6 +171,7 @@ export default class DataProcessor { static get metricFunctions() { return { groupBy: this.groupByWrapper, + aggregateBy: this.aggregateByWrapper, average: _.partial(this.aggregateWrapper, this.AVERAGE), min: _.partial(this.aggregateWrapper, this.MIN), max: _.partial(this.aggregateWrapper, this.MAX), diff --git a/src/datasource-zabbix/metricFunctions.js b/src/datasource-zabbix/metricFunctions.js index aa0351c..024aa0d 100644 --- a/src/datasource-zabbix/metricFunctions.js +++ b/src/datasource-zabbix/metricFunctions.js @@ -73,6 +73,16 @@ addFuncDef({ defaultParams: ['1m'], }); +addFuncDef({ + name: 'aggregateBy', + category: 'Aggregate', + params: [ + { name: 'interval', type: 'string' }, + { name: 'function', type: 'string', options: ['avg', 'min', 'max', 'median'] } + ], + defaultParams: ['1m', 'avg'], +}); + addFuncDef({ name: 'trendValue', category: 'Trends', diff --git a/src/datasource-zabbix/partials/query.editor.html b/src/datasource-zabbix/partials/query.editor.html index eb858c5..a88335e 100644 --- a/src/datasource-zabbix/partials/query.editor.html +++ b/src/datasource-zabbix/partials/query.editor.html @@ -12,14 +12,14 @@
-
-
+
+
- +
-
-
+
+
- +
- +
- - -
-
-
+
+
- +
- +
+ +
+ + +
- +
-
-
+
+
+
- + - + +
+ + +
+
+ + +
diff --git a/src/datasource-zabbix/query.controller.js b/src/datasource-zabbix/query.controller.js index 5b609dc..ddd23b7 100644 --- a/src/datasource-zabbix/query.controller.js +++ b/src/datasource-zabbix/query.controller.js @@ -26,9 +26,9 @@ export class ZabbixQueryController extends QueryCtrl { this.templateSrv = templateSrv; this.editorModes = { - 0: {value: 'num', text: 'Numeric metrics', mode: 0}, + 0: {value: 'num', text: 'Metrics', mode: 0}, 1: {value: 'itservice', text: 'IT Services', mode: 1}, - 2: {value: 'text', text: 'Text metrics', mode: 2} + 2: {value: 'text', text: 'Text', mode: 2} }; // Map functions for bs-typeahead @@ -48,7 +48,8 @@ export class ZabbixQueryController extends QueryCtrl { var scopeDefaults = { metric: {}, - oldTarget: _.cloneDeep(this.target) + oldTarget: _.cloneDeep(this.target), + queryOptionsText: this.renderQueryOptionsText() }; _.defaults(this, scopeDefaults); @@ -60,6 +61,9 @@ export class ZabbixQueryController extends QueryCtrl { application: { filter: "" }, item: { filter: "" }, functions: [], + options: { + showDisabledItems: false + } }; _.defaults(target, targetDefaults); @@ -155,7 +159,7 @@ export class ZabbixQueryController extends QueryCtrl { return self.zabbix .getItems(undefined, appids, itemtype) .then(items => { - if (!self.target.showDisabledItems) { + if (!self.target.options.showDisabledItems) { items = _.filter(items, {'status': '0'}); } self.metric.itemList = items; @@ -168,7 +172,7 @@ export class ZabbixQueryController extends QueryCtrl { return self.zabbix .getItems(hostids, undefined, itemtype) .then(items => { - if (!self.target.showDisabledItems) { + if (!self.target.options.showDisabledItems) { items = _.filter(items, {'status': '0'}); } self.metric.itemList = items; @@ -257,6 +261,34 @@ export class ZabbixQueryController extends QueryCtrl { } } + toggleQueryOptions() { + this.showQueryOptions = !this.showQueryOptions; + } + + onQueryOptionChange() { + this.queryOptionsText = this.renderQueryOptionsText(); + this.onTargetBlur(); + } + + renderQueryOptionsText() { + var optionsMap = { + showDisabledItems: "Show disabled items" + }; + var options = []; + _.forOwn(this.target.options, (value, key) => { + if (value) { + if (value === true) { + // Show only option name (if enabled) for boolean options + options.push(optionsMap[key]); + } else { + // Show "option = value" for another options + options.push(optionsMap[key] + " = " + value); + } + } + }); + return "Options: " + options.join(', '); + } + /** * Switch query editor to specified mode. * Modes: diff --git a/src/plugin.json b/src/plugin.json index a0e7240..e590738 100644 --- a/src/plugin.json +++ b/src/plugin.json @@ -31,8 +31,8 @@ {"name": "Metric Editor", "path": "img/screenshot-metric_editor.png"}, {"name": "Triggers", "path": "img/screenshot-triggers.png"} ], - "version": "3.0.0-beta7", - "updated": "2016-04-14" + "version": "3.0.0-beta8", + "updated": "2016-04-30" }, "includes": [