[Noob with Flux] Create dynamic Dashboard in Grafana

Hello to everyone,

I’m a new user of flux, and it’s really hard to understand.
I’d like to create dynamic dashboard in Grafana. The goal is to have, for example, the hostname of a router, when I select his location from a first picker.
I setup two variable :
For the location :
from(bucket: “telegraf/autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “snmp”)
|> filter(fn: (r) => r["_field"] == “Localisation”)
|> keep(columns: ["_value"])
|> distinct()
|> yield(name: “distinct”)

My picker is ok, I can show al locations of my routers. Now I want to have a second picker updated. I create a new variable like that :
from(bucket: “telegraf/autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_field"] == “$location”)
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: “_value”)
|> group()
|> distinct(column: “hostname”)

But it return “none”.
The sad thing is I’m able to do the revert (start from hostname to have localisation), but it’s not what I need.

Could you help me with this ?

Regards,

Tiki_

Hello,

I finally did it like that :

from(bucket: “telegraf/autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “snmp”)
|> filter(fn: (r) => r["_field"] == “Localisation”
|> keep(columns: ["_value"])
|> distinct()

And

from(bucket: “telegraf/autogen”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == “snmp”)
|> filter(fn: (r) => r["_field"] == “Localisation” and r._value == “${chantier}”)
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: “_value”)
|> group()
|> distinct(column: “hostname”)
|> yield(name: “distinct”)

Regards

Thanks for sharing your solution!
You might also be interested in the following flux functions: