SHOW TAG VALUES WITH KEY in Flux



Published: 2022-08-01 16:13:50 +0000
Categories: Flux,

Language

Flux

Description

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

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"])

Keywords

influxdb, flux, schema, tag values, filter,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter