Fluxql grafana variables

I am trying to define a variable named “Host” based on the snmp user agents i have stored in an Influx bucket, but i am missing something …

from(bucket: “bucket1”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“agent_host”]

Hi @mckinley and welcome to the Grafana forum.

Did you define the variable in this screen? In my example, it’s a tag called “region”.

import "influxdata/influxdb/schema"
    bucket: "EIAtest7",
    tag: "region"

In my Flux query, this is how I allow one to select multiple regions:

  |> filter(fn: (r) => r["region"] =~ /^${region:regex}$/ )


Hi Grant,
Thanks for the reply. I’m not sure i follow your logic here. Do i need to modify the database schema to define a variable?
This is what the output from influxdb looks like:

I simply want to be able to iterate over all the host agents in my influxdb

Hi @mckinley ,
grant2 already provide solution for you. You just need to adjust bucket name and tag, so in your case your query for dashboard variable should look like:

import "influxdata/influxdb/schema"
    bucket: "bucket1",
    tag: "agent_host"

and all unique agents should be displayed.

You can take a look at influxdb schema tagvalues documentation.

Everything is done in Grafana ( open dashboard → Settings → Variables → New variable ). Nothing will be changed or written in influxdb.


Best regards,

1 Like

Thank you very much.
It seems to be working, but im not sure why. But maybe that’s an exercise best left to the “reader”