Custom dashboard variables in InfluxDB
fastai
Custom dashboard variables in InfluxDB
You can create a new variable in the Data Explorer, in the Settings or import from InfluxDB in JSON. Here we review the steps to create a variable in the Data Explorer
Dashboard variable types
There are three types of dashboard variables. The types refert to the structuring of the variable’s possible values.
- Map: stores values as key/value pairs in a comma separated format. The UI presents the keys but works with the values.
- Query: uses values from a Flux query’s
_valuecolumn. (If the values are in another colum, you can first rename that column to_value) - CSV: uses a CSV-formatted list.
Create variable in Data Explorer
- Open the Data Explorer
- Build a query with the Query Builder or the Script Editor
- Select Save As at the top right corner
- Select the Variable tab.
- Add a name for the variable and click Save as Variable
Viewing dashboard variables
You can view variables which belong to your organization.
You can review them in two places:
- In the Settings menu on the Variables tab
- In the Data Explorer, in Script Editor mode under the Variables tab.
Update, export, or delete a dashboard variable
- Open the Settings menu in the navigation bar
- Select the Variables tab.
- For update, click on a variable’s name in the list. To rename, export, or delete, select the appropriate icon in the top right corner of their card.
Variable queries
List buckets
// List buckets in the current organization
buckets()
// Rename the `name` column to `_value`
|> rename(columns: {"name": "_value"})
// Return a table only with the specific columns
|> keep(columns: ["_value"])
List measurements
// List all measurements in the bucket
// Import the schema package
import "influxdata/influxdb/schema"
// List the measurements of the specified bucket
schema.measurements(bucket: "bucket-name")
List fields in a measurement
List field in the specified bucket + measurement.
// Import the schema package
import "influxdata/influxdb/schema"
schema.measurementTagValues(
bucket: "bucket-name",
measurement: "measurement-name",
tag: "_field"
)
List unique tag values
List the unique values of the host tag.
import "influxdata/influxdb/schema"
schame.measurementTagValues(bucket: "bucket-name", tag: "host")