SHOW TAG VALUES WITH KEY in Flux (Flux)
When creating a filter variable in a Chronograf or Grafana dashboard, you'll sometimes want to dynamically select tag values to use as options in the dropdown.
In InfluxQL this is achieved with a SHOW TAG VALUES query like the following
SHOW TAG VALUES ON "telegraf" FROM "cpu" WITH KEY = "host"
This snippet shows how to use Flux to list the values of a specific tag that occur within the dashboard's timerange
Similar To
Details
- Language: Flux
Snippet
from(bucket: <bucket_name>)
|> range(start: <start_time>)
|> filter(fn: (r) => r._measurement == <measurement_name>)
|> keyValues(keyColumns: [<tag_name>])
|> group()
|> keep(columns: ["_value"])
Usage Example
from(bucket: "telegraf")
|> range(start: v.timeRangeStart)
|> filter(fn: (r) => r._measurement == "cpu")
|> keyValues(keyColumns: ["host"])
|> group()
|> keep(columns: ["_value"])