Dashboard variables in InfluxDB
Dashboard variables in InfluxDB
Variables
Dashboard variables are useful when you would like to modify dashboard cells without editing the original queries based on which the dashboard is built. You can also use Flux to build queries for dashboard cells.
Dashboard variables can be
- Predefined:
v.timeRangeStart,v.timeRangeStop,v.windowPeriod - Custom: defined in the user interface
Quering a variable
Variables are stored in a v standing for a particular dashboard
from(bucket: v.bucket)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == v._measurement and r.field == v.field)
|> aggregateWindow(every: v.windowPeriod, fn: mean)
Adding a variable
- Check available variables on the right hand side under the Variables tab
- Select the name of the variable you would like to add
- Select a value from the Value dropdown
Linking a dashboard with variables
After adding the variable, the dashboard’s url will have the following structure appended to its end &vars[variable_name]=value. This allows you to directly share the dashboard with the variable included with a simple url.
Custom variables
You can create variables for your dashboard in the following ways: - in the Data Explorer - in Settings - via import
Naming restrictions
Variable names has to - be unique - start with and underscore ‘_’ - they cannot be one of the Flux reserved keywords: and, import, not, return, option, test, empty, in, or, package, and builtin.