Reputation: 151
I want to get all keys for a particular measurement from a particular bucket to use in a variable on a Grafana dashboard.
I'm fairly certain that I'm starting correctly:
from(bucket: "my_bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "host")
How do you get a list of the keys from the measurement host
?
I've tried adding:
|> keys()
and
|> columns()
|> keep(columns: ["_value"])
|> group()
|> distinct()
I suspect it might involve:
|> schema.tagKeys()
But I can't import schema in flux cloud data explorer.
I know it must be something simple, but I can't find the answer in documentation or searches on here.
EDIT: Didn't realise this, but host contains float and string values.
Upvotes: 0
Views: 1023
Reputation: 13
I'm pretty new to flux query, but I found you can get unique keys from a column (in this case 'site') using the following.
from(bucket: "my_bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "host")
|> group(columns: ["site"])
|> unique(column: "site")
|> sort(columns: ["site"], desc: false)
Upvotes: 1