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
_value
column. (If the values are in another colum, you can first rename that column to_value
) - CSV: uses a CSV-formatted list.
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")