Commit 26756f86 by Marcus Efraimsson Committed by GitHub

Merge pull request #13148 from svenklemm/postgres-min-interval

Add min time interval support for SQL datasources
parents 4ce41c16 db639684
...@@ -154,7 +154,7 @@ Since not all datasources have the same configuration settings we only have the ...@@ -154,7 +154,7 @@ Since not all datasources have the same configuration settings we only have the
| tlsAuthWithCACert | boolean | *All* | Enable TLS authentication using CA cert | | tlsAuthWithCACert | boolean | *All* | Enable TLS authentication using CA cert |
| tlsSkipVerify | boolean | *All* | Controls whether a client verifies the server's certificate chain and host name. | | tlsSkipVerify | boolean | *All* | Controls whether a client verifies the server's certificate chain and host name. |
| graphiteVersion | string | Graphite | Graphite version | | graphiteVersion | string | Graphite | Graphite version |
| timeInterval | string | Elastic, InfluxDB & Prometheus | Lowest interval/step value that should be used for this data source | | timeInterval | string | Prometheus, Elasticsearch, InfluxDB, MySQL, PostgreSQL & MSSQL | Lowest interval/step value that should be used for this data source |
| esVersion | number | Elastic | Elasticsearch version as a number (2/5/56) | | esVersion | number | Elastic | Elasticsearch version as a number (2/5/56) |
| timeField | string | Elastic | Which field that should be used as timestamp | | timeField | string | Elastic | Which field that should be used as timestamp |
| interval | string | Elastic | Index date time format | | interval | string | Elastic | Index date time format |
......
...@@ -6,7 +6,7 @@ type = "docs" ...@@ -6,7 +6,7 @@ type = "docs"
[menu.docs] [menu.docs]
name = "Microsoft SQL Server" name = "Microsoft SQL Server"
parent = "datasources" parent = "datasources"
weight = 7 weight = 8
+++ +++
# Using Microsoft SQL Server in Grafana # Using Microsoft SQL Server in Grafana
...@@ -33,6 +33,24 @@ Name | Description ...@@ -33,6 +33,24 @@ Name | Description
*User* | Database user's login/username *User* | Database user's login/username
*Password* | Database user's password *Password* | Database user's password
### Min time interval
A lower limit for the [$__interval](/reference/templating/#the-interval-variable) and [$__interval_ms](/reference/templating/#the-interval-ms-variable) variables.
Recommended to be set to write frequency, for example `1m` if your data is written every minute.
This option can also be overridden/configured in a dashboard panel under data source options. It's important to note that this value **needs** to be formatted as a
number followed by a valid time identifier, e.g. `1m` (1 minute) or `30s` (30 seconds). The following time identifiers are supported:
Identifier | Description
------------ | -------------
`y` | year
`M` | month
`w` | week
`d` | day
`h` | hour
`m` | minute
`s` | second
`ms` | millisecond
### Database User Permissions (Important!) ### Database User Permissions (Important!)
The database user you specify when you add the data source should only be granted SELECT permissions on The database user you specify when you add the data source should only be granted SELECT permissions on
......
...@@ -36,6 +36,24 @@ Name | Description ...@@ -36,6 +36,24 @@ Name | Description
*User* | Database user's login/username *User* | Database user's login/username
*Password* | Database user's password *Password* | Database user's password
### Min time interval
A lower limit for the [$__interval](/reference/templating/#the-interval-variable) and [$__interval_ms](/reference/templating/#the-interval-ms-variable) variables.
Recommended to be set to write frequency, for example `1m` if your data is written every minute.
This option can also be overridden/configured in a dashboard panel under data source options. It's important to note that this value **needs** to be formatted as a
number followed by a valid time identifier, e.g. `1m` (1 minute) or `30s` (30 seconds). The following time identifiers are supported:
Identifier | Description
------------ | -------------
`y` | year
`M` | month
`w` | week
`d` | day
`h` | hour
`m` | minute
`s` | second
`ms` | millisecond
### Database User Permissions (Important!) ### Database User Permissions (Important!)
The database user you specify when you add the data source should only be granted SELECT permissions on The database user you specify when you add the data source should only be granted SELECT permissions on
......
...@@ -34,6 +34,23 @@ Name | Description ...@@ -34,6 +34,23 @@ Name | Description
*Version* | This option determines which functions are available in the query builder (only available in Grafana 5.3+). *Version* | This option determines which functions are available in the query builder (only available in Grafana 5.3+).
*TimescaleDB* | TimescaleDB is a time-series database built as a PostgreSQL extension. If enabled, Grafana will use `time_bucket` in the `$__timeGroup` macro and display TimescaleDB specific aggregate functions in the query builder (only available in Grafana 5.3+). *TimescaleDB* | TimescaleDB is a time-series database built as a PostgreSQL extension. If enabled, Grafana will use `time_bucket` in the `$__timeGroup` macro and display TimescaleDB specific aggregate functions in the query builder (only available in Grafana 5.3+).
### Min time interval
A lower limit for the [$__interval](/reference/templating/#the-interval-variable) and [$__interval_ms](/reference/templating/#the-interval-ms-variable) variables.
Recommended to be set to write frequency, for example `1m` if your data is written every minute.
This option can also be overridden/configured in a dashboard panel under data source options. It's important to note that this value **needs** to be formatted as a
number followed by a valid time identifier, e.g. `1m` (1 minute) or `30s` (30 seconds). The following time identifiers are supported:
Identifier | Description
------------ | -------------
`y` | year
`M` | month
`w` | week
`d` | day
`h` | hour
`m` | minute
`s` | second
`ms` | millisecond
### Database User Permissions (Important!) ### Database User Permissions (Important!)
......
...@@ -245,7 +245,7 @@ Grafana has global built-in variables that can be used in expressions in the que ...@@ -245,7 +245,7 @@ Grafana has global built-in variables that can be used in expressions in the que
### The $__interval Variable ### The $__interval Variable
This $__interval variable is similar to the `auto` interval variable that is described above. It can be used as a parameter to group by time (for InfluxDB), Date histogram interval (for Elasticsearch) or as a *summarize* function parameter (for Graphite). This $__interval variable is similar to the `auto` interval variable that is described above. It can be used as a parameter to group by time (for InfluxDB, MySQL, Postgres, MSSQL), Date histogram interval (for Elasticsearch) or as a *summarize* function parameter (for Graphite).
Grafana automatically calculates an interval that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval. It is more efficient to group by 1 day than by 10s when looking at 3 months of data and the graph will look the same and the query will be faster. The `$__interval` is calculated using the time range and the width of the graph (the number of pixels). Grafana automatically calculates an interval that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval. It is more efficient to group by 1 day than by 10s when looking at 3 months of data and the graph will look the same and the query will be faster. The `$__interval` is calculated using the time range and the width of the graph (the number of pixels).
......
...@@ -5,12 +5,14 @@ export class MssqlDatasource { ...@@ -5,12 +5,14 @@ export class MssqlDatasource {
id: any; id: any;
name: any; name: any;
responseParser: ResponseParser; responseParser: ResponseParser;
interval: string;
/** @ngInject */ /** @ngInject */
constructor(instanceSettings, private backendSrv, private $q, private templateSrv) { constructor(instanceSettings, private backendSrv, private $q, private templateSrv) {
this.name = instanceSettings.name; this.name = instanceSettings.name;
this.id = instanceSettings.id; this.id = instanceSettings.id;
this.responseParser = new ResponseParser(this.$q); this.responseParser = new ResponseParser(this.$q);
this.interval = (instanceSettings.jsonData || {}).timeInterval;
} }
interpolateVariable(value, variable) { interpolateVariable(value, variable) {
......
...@@ -29,6 +29,21 @@ ...@@ -29,6 +29,21 @@
</div> </div>
</div> </div>
<h3 class="page-heading">MSSQL details</h3>
<div class="gf-form-group">
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9">Min time interval</span>
<input type="text" class="gf-form-input width-6" ng-model="ctrl.current.jsonData.timeInterval" spellcheck='false' placeholder="1m"></input>
<info-popover mode="right-absolute">
A lower limit for the auto group by time interval. Recommended to be set to write frequency,
for example <code>1m</code> if your data is written every minute.
</info-popover>
</div>
</div>
</div>
<div class="gf-form-group"> <div class="gf-form-group">
<div class="grafana-info-box"> <div class="grafana-info-box">
<h5>User Permission</h5> <h5>User Permission</h5>
......
...@@ -17,5 +17,10 @@ ...@@ -17,5 +17,10 @@
"alerting": true, "alerting": true,
"annotations": true, "annotations": true,
"metrics": true "metrics": true,
"queryOptions": {
"minInterval": true
}
} }
...@@ -5,12 +5,14 @@ export class MysqlDatasource { ...@@ -5,12 +5,14 @@ export class MysqlDatasource {
id: any; id: any;
name: any; name: any;
responseParser: ResponseParser; responseParser: ResponseParser;
interval: string;
/** @ngInject */ /** @ngInject */
constructor(instanceSettings, private backendSrv, private $q, private templateSrv) { constructor(instanceSettings, private backendSrv, private $q, private templateSrv) {
this.name = instanceSettings.name; this.name = instanceSettings.name;
this.id = instanceSettings.id; this.id = instanceSettings.id;
this.responseParser = new ResponseParser(this.$q); this.responseParser = new ResponseParser(this.$q);
this.interval = (instanceSettings.jsonData || {}).timeInterval;
} }
interpolateVariable(value, variable) { interpolateVariable(value, variable) {
......
...@@ -24,6 +24,21 @@ ...@@ -24,6 +24,21 @@
</div> </div>
</div> </div>
<h3 class="page-heading">MySQL details</h3>
<div class="gf-form-group">
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9">Min time interval</span>
<input type="text" class="gf-form-input width-6" ng-model="ctrl.current.jsonData.timeInterval" spellcheck='false' placeholder="1m"></input>
<info-popover mode="right-absolute">
A lower limit for the auto group by time interval. Recommended to be set to write frequency,
for example <code>1m</code> if your data is written every minute.
</info-popover>
</div>
</div>
</div>
<div class="gf-form-group"> <div class="gf-form-group">
<div class="grafana-info-box"> <div class="grafana-info-box">
<h5>User Permission</h5> <h5>User Permission</h5>
......
...@@ -18,5 +18,10 @@ ...@@ -18,5 +18,10 @@
"alerting": true, "alerting": true,
"annotations": true, "annotations": true,
"metrics": true "metrics": true,
"queryOptions": {
"minInterval": true
}
} }
...@@ -8,6 +8,7 @@ export class PostgresDatasource { ...@@ -8,6 +8,7 @@ export class PostgresDatasource {
jsonData: any; jsonData: any;
responseParser: ResponseParser; responseParser: ResponseParser;
queryModel: PostgresQuery; queryModel: PostgresQuery;
interval: string;
/** @ngInject */ /** @ngInject */
constructor(instanceSettings, private backendSrv, private $q, private templateSrv, private timeSrv) { constructor(instanceSettings, private backendSrv, private $q, private templateSrv, private timeSrv) {
...@@ -16,6 +17,7 @@ export class PostgresDatasource { ...@@ -16,6 +17,7 @@ export class PostgresDatasource {
this.jsonData = instanceSettings.jsonData; this.jsonData = instanceSettings.jsonData;
this.responseParser = new ResponseParser(this.$q); this.responseParser = new ResponseParser(this.$q);
this.queryModel = new PostgresQuery({}); this.queryModel = new PostgresQuery({});
this.interval = (instanceSettings.jsonData || {}).timeInterval;
} }
interpolateVariable(value, variable) { interpolateVariable(value, variable) {
......
...@@ -61,6 +61,16 @@ ...@@ -61,6 +61,16 @@
</label> </label>
</div> </div>
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9">Min time interval</span>
<input type="text" class="gf-form-input width-6" ng-model="ctrl.current.jsonData.timeInterval" spellcheck='false' placeholder="1m"></input>
<info-popover mode="right-absolute">
A lower limit for the auto group by time interval. Recommended to be set to write frequency,
for example <code>1m</code> if your data is written every minute.
</info-popover>
</div>
</div>
<div class="grafana-info-box alert alert-info" ng-show="ctrl.showTimescaleDBHelp"> <div class="grafana-info-box alert alert-info" ng-show="ctrl.showTimescaleDBHelp">
<div class="alert-body"> <div class="alert-body">
<p> <p>
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
"alerting": true, "alerting": true,
"annotations": true, "annotations": true,
"metrics": true "metrics": true,
"queryOptions": {
"minInterval": true
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment