Influx 2.7 - using dashboard variable in tasks flux script


I created some dashboard variables via the Influx 2 UI. I would like to use those variables in a Flux script that is part of a task or part of a notebook.

The v record does not appear to have access to the dashboard variables. Can someone please let me know if it is possible to use the dashboard variables for this use case.


Hello @Greg_Svitak
Welcome! Wow I honestly can’t remember if you can use dashboard variables in tasks. But I think what you might want is parameterized queries instead:

hi @Anaisdg thanks you for your input!

I am currently just using tasks inside of Influxdb. I am not trying to integrate with an external application. So it seems like the API approach is a little more complex than what I need.

My idea of using dashboard variables is based on what I understand is available in Flux script today.The real root question is that I have per environment variables that I want to set per environment. These variables are URL for HTTP post etc that are not secrets. IMHO, I feel like these variable values should be easily maintained via the Influx UI.

Any suggestions on a better approach would be appreciated.


Hello @Greg_Svitak,
Yes I agree. Unfortunately I don’t think you can use dashboard variables like that within a flux task.
In flux you can do:

// Define the parameters
option mybucket = "cpu"

from(bucket: mybucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "cpu")
  |> filter(fn: (r) => r["_field"] == "usage_system")
  |> filter(fn: (r) => r["cpu"] == "cpu-total")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

This was actually a long time request from me now that I’m remembering because it would be nice to parameterize some common queries and store them as a function with inputs and save as a variable so I could just reference like basicquery(-10min) instead of querying for cpu, cpu-total, etc each time. or even be able to do like from(bucket: “cpu) |> range() |>typtical_query where typical query is |> filter(fn: (r) => r[”_measurement"] == “cpu”) |> filter(fn: (r) => r[“_field”] == “usage_system”) |> filter(fn: (r) => r[“cpu”] == “cpu-total”)