diff --git a/pkg/plugins/datasource_plugin.go b/pkg/plugins/datasource_plugin.go index e46c2709649..e62157a7a13 100644 --- a/pkg/plugins/datasource_plugin.go +++ b/pkg/plugins/datasource_plugin.go @@ -8,15 +8,13 @@ import ( type DataSourcePlugin struct { FrontendPluginBase - Annotations bool `json:"annotations"` - Metrics bool `json:"metrics"` - Alerting bool `json:"alerting"` - MinInterval bool `json:"minInterval,omitempty"` - CacheTimeout bool `json:"cacheTimeout,omitempty"` - MaxDataPoints bool `json:"maxDataPoints,omitempty"` - BuiltIn bool `json:"builtIn,omitempty"` - Mixed bool `json:"mixed,omitempty"` - HasHelp bool `json:"hasHelp,omitempty"` + Annotations bool `json:"annotations"` + Metrics bool `json:"metrics"` + Alerting bool `json:"alerting"` + QueryOptions map[string]bool `json:"queryOptions,omitempty"` + BuiltIn bool `json:"builtIn,omitempty"` + Mixed bool `json:"mixed,omitempty"` + HasQueryHelp bool `json:"hasQueryHelp,omitempty"` Routes []*AppPluginRoute `json:"-"` } @@ -31,12 +29,12 @@ func (p *DataSourcePlugin) Load(decoder *json.Decoder, pluginDir string) error { } // look for help markdown - helpPath := filepath.Join(p.PluginDir, "HELP.md") + helpPath := filepath.Join(p.PluginDir, "QUERY_HELP.md") if _, err := os.Stat(helpPath); os.IsNotExist(err) { - helpPath = filepath.Join(p.PluginDir, "help.md") + helpPath = filepath.Join(p.PluginDir, "query_help.md") } if _, err := os.Stat(helpPath); err == nil { - p.HasHelp = true + p.HasQueryHelp = true } DataSources[p.Id] = p diff --git a/public/app/core/utils/kbn.js b/public/app/core/utils/kbn.js index 6f8340d5940..37888fb10ac 100644 --- a/public/app/core/utils/kbn.js +++ b/public/app/core/utils/kbn.js @@ -163,21 +163,15 @@ function($, _) { ms: 0.001 }; - kbn.calculateInterval = function(range, resolution, userInterval) { + kbn.calculateInterval = function(range, resolution, lowLimitInterval) { var lowLimitMs = 1; // 1 millisecond default low limit - var intervalMs, lowLimitInterval; + var intervalMs; - if (userInterval) { - if (userInterval[0] === '>') { - lowLimitInterval = userInterval.slice(1); - lowLimitMs = kbn.interval_to_ms(lowLimitInterval); - } - else { - return { - intervalMs: kbn.interval_to_ms(userInterval), - interval: userInterval, - }; + if (lowLimitInterval) { + if (lowLimitInterval[0] === '>') { + lowLimitInterval = lowLimitInterval.slice(1); } + lowLimitMs = kbn.interval_to_ms(lowLimitInterval); } intervalMs = kbn.round_interval((range.to.valueOf() - range.from.valueOf()) / resolution); diff --git a/public/app/features/panel/metrics_tab.ts b/public/app/features/panel/metrics_tab.ts index e57a685d4e4..4feaf516438 100644 --- a/public/app/features/panel/metrics_tab.ts +++ b/public/app/features/panel/metrics_tab.ts @@ -16,12 +16,10 @@ export class MetricsTabCtrl { addQueryDropdown: any; queryTroubleshooterOpen: boolean; helpOpen: boolean; - hasHelp: boolean; - helpHtml: string; - hasMinInterval: boolean; - hasCacheTimeout: boolean; - hasMaxDataPoints: boolean; optionsOpen: boolean; + hasQueryHelp: boolean; + helpHtml: string; + queryOptions: any; /** @ngInject */ constructor($scope, private $sce, private datasourceSrv, private backendSrv, private $timeout) { @@ -46,10 +44,8 @@ export class MetricsTabCtrl { } updateDatasourceOptions() { - this.hasHelp = this.current.meta.hasHelp; - this.hasMinInterval = this.current.meta.minInterval === true; - this.hasCacheTimeout = this.current.meta.cacheTimeout === true; - this.hasMaxDataPoints = this.current.meta.maxDataPoints === true; + this.hasQueryHelp = this.current.meta.hasQueryHelp; + this.queryOptions = this.current.meta.queryOptions; } getOptions(includeBuiltin) { @@ -89,7 +85,7 @@ export class MetricsTabCtrl { this.queryTroubleshooterOpen = false; this.helpOpen = !this.helpOpen; - this.backendSrv.get(`/api/plugins/${this.current.meta.id}/markdown/help`).then(res => { + this.backendSrv.get(`/api/plugins/${this.current.meta.id}/markdown/query_help`).then(res => { var md = new Remarkable(); this.helpHtml = this.$sce.trustAsHtml(md.render(res)); }); diff --git a/public/app/features/panel/partials/metrics_tab.html b/public/app/features/panel/partials/metrics_tab.html index d9ad033e9ea..e15f7f3f552 100644 --- a/public/app/features/panel/partials/metrics_tab.html +++ b/public/app/features/panel/partials/metrics_tab.html @@ -15,12 +15,12 @@
-
+
Options
-
+
@@ -33,8 +33,8 @@
-
-
+
+
@@ -43,7 +43,7 @@ string and $__interval_ms for numeric variable that can be used in math expressions.
-
+
@@ -51,7 +51,7 @@ cache timeout. Specify a numeric value in seconds.
-
+
diff --git a/public/app/features/templating/interval_variable.ts b/public/app/features/templating/interval_variable.ts index 10977596057..ffd30392cc7 100644 --- a/public/app/features/templating/interval_variable.ts +++ b/public/app/features/templating/interval_variable.ts @@ -54,7 +54,7 @@ export class IntervalVariable implements Variable { this.options.unshift({ text: 'auto', value: '$__auto_interval' }); } - var res = kbn.calculateInterval(this.timeSrv.timeRange(), this.auto_count, (this.auto_min ? ">"+this.auto_min : null)); + var res = kbn.calculateInterval(this.timeSrv.timeRange(), this.auto_count, this.auto_min); this.templateSrv.setGrafanaVariable('$__auto_interval', res.interval); } diff --git a/public/app/plugins/datasource/elasticsearch/partials/config.html b/public/app/plugins/datasource/elasticsearch/partials/config.html index 03662a9693b..8b5f3ba8a8a 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/config.html +++ b/public/app/plugins/datasource/elasticsearch/partials/config.html @@ -25,13 +25,14 @@ Version
- -
- -

Default query settings

-
-
- Group by time interval - +
+
+ Min interval + + + A lower limit for the auto group by time interval. Recommended to be set to write frequency, + for example 1m if your data is written every minute. + +
diff --git a/public/app/plugins/datasource/graphite/plugin.json b/public/app/plugins/datasource/graphite/plugin.json index 6802366691e..366c56f62c8 100644 --- a/public/app/plugins/datasource/graphite/plugin.json +++ b/public/app/plugins/datasource/graphite/plugin.json @@ -10,8 +10,11 @@ "metrics": true, "alerting": true, "annotations": true, - "maxDataPoints": true, - "cacheTimeout": true, + + "queryOptions": { + "maxDataPoints": true, + "cacheTimeout": true + }, "info": { "author": { diff --git a/public/app/plugins/datasource/graphite/help.md b/public/app/plugins/datasource/graphite/query_help.md similarity index 100% rename from public/app/plugins/datasource/graphite/help.md rename to public/app/plugins/datasource/graphite/query_help.md diff --git a/public/app/plugins/datasource/influxdb/partials/config.html b/public/app/plugins/datasource/influxdb/partials/config.html index 27b28ba59de..9fe599fc431 100644 --- a/public/app/plugins/datasource/influxdb/partials/config.html +++ b/public/app/plugins/datasource/influxdb/partials/config.html @@ -24,10 +24,14 @@
-
- Default group by time - - +
+
+ Min interval + + + A lower limit for the auto group by time interval. Recommended to be set to write frequency, + for example 1m if your data is written every minute. + +
diff --git a/public/app/plugins/datasource/influxdb/plugin.json b/public/app/plugins/datasource/influxdb/plugin.json index 097b6594536..7300940cbb8 100644 --- a/public/app/plugins/datasource/influxdb/plugin.json +++ b/public/app/plugins/datasource/influxdb/plugin.json @@ -7,7 +7,10 @@ "metrics": true, "annotations": true, "alerting": true, - "minInterval": true, + + "queryOptions": { + "minInterval": true + }, "info": { "author": { diff --git a/public/app/plugins/datasource/influxdb/query_help.md b/public/app/plugins/datasource/influxdb/query_help.md new file mode 100644 index 00000000000..c12c8122efd --- /dev/null +++ b/public/app/plugins/datasource/influxdb/query_help.md @@ -0,0 +1,22 @@ +#### Alias patterns +- replaced with measurement name +- $measurement = replaced with measurement name +- $1 - $9 = replaced with part of measurement name (if you separate your measurement name with dots) +- $col = replaced with column name +- $tag_exampletag = replaced with the value of the exampletag tag +- You can also use [[tag_exampletag]] pattern replacement syntax + +#### Stacking and fill +- When stacking is enabled it is important that points align +- If there are missing points for one series it can cause gaps or missing bars +- You must use fill(0), and select a group by time low limit +- Use the group by time option below your queries and specify for example >10s if your metrics are written every 10 seconds +- This will insert zeros for series that are missing measurements and will make stacking work properly + +#### Group by time +- Group by time is important, otherwise the query could return many thousands of datapoints that will slow down Grafana +- Leave the group by time field empty for each query and it will be calculated based on time range and pixel width of the graph +- If you use fill(0) or fill(null) set a low limit for the auto group by time interval +- The low limit can only be set in the group by time option below your queries +- You set a low limit by adding a greater sign before the interval +- Example: >60s if you write metrics to InfluxDB every 60 seconds diff --git a/public/test/core/utils/kbn_specs.js b/public/test/core/utils/kbn_specs.js index 4fba92f727f..0b7f4b4f2bc 100644 --- a/public/test/core/utils/kbn_specs.js +++ b/public/test/core/utils/kbn_specs.js @@ -143,8 +143,8 @@ define([ expect(res.intervalMs).to.be(500); }); - it('fixed user interval', function() { - var range = { from: dateMath.parse('now-10m'), to: dateMath.parse('now') }; + it('fixed user min interval', function() { + var range = {from: dateMath.parse('now-10m'), to: dateMath.parse('now')}; var res = kbn.calculateInterval(range, 1600, '10s'); expect(res.interval).to.be('10s'); expect(res.intervalMs).to.be(10000);