Flux's variables

  • What Grafana version and what operating system are you using?

Docker / grafana version 10.0.2 + InfluxDB v2.7.1

  • What are you trying to achieve?

Using Flux’s variables to perform multiple aggregations and Grafana’s variables for the dashboard. I would like to get the two series with just one query, because currently I have to execute one query to get the output and a second query to get the input.

  • How are you trying to achieve it?
dataRetuned = from(bucket: "${BUCKET}")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "ifXTable")
  |> filter(fn: (r) => r["sysName"] == "${DEVICE}")
  |> filter(fn: (r) => r["ifName"] == "${DEVICE}")
  |> fill(usePrevious: true)

output = dataReturned
  |> filter(fn: (r) => r["_field"] == "output")
  |> map(fn: (r) => ({r with _value: float(v: r._value) * 8.0}))
  |> derivative(unit: 1s, nonNegative: true)
  |> yield(name: "output")

input = dataReturned
  |> filter(fn: (r) => r["_field"] == "input")
  |> map(fn: (r) => ({r with _value: float(v: r._value) * 8.0}))
  |> derivative(unit: 1s, nonNegative: true)
  |> yield(name: "input")
  • What happened?

No Data returned.

If I manually enter values instead of the dashboard variables, I get the answers

For example:

dataReturned = from(bucket: "Metrics")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "ifXTable")
  |> filter(fn: (r) => r["sysName"] == "sw-core")
  |> filter(fn: (r) => r["ifName"] == "gi1")
  |> fill(usePrevious: true)

output = dataReturned
  |> filter(fn: (r) => r["_field"] == "output")
  |> map(fn: (r) => ({r with _value: float(v: r._value) * 8.0}))
  |> derivative(unit: 1s, nonNegative: true)
  |> yield(name: "output")

input = dataReturned
  |> filter(fn: (r) => r["_field"] == "input")
  |> map(fn: (r) => ({r with _value: float(v: r._value) * 8.0}))
  |> derivative(unit: 1s, nonNegative: true)
  |> yield(name: "input")

Thanks in advance for any helps,
Andrea

Maybe try removing the double quotes

no, unfortunately it doesn’t work :pensive:

1 Like
  |> filter(fn: (r) => r["sysName"] == "${DEVICE}")
  |> filter(fn: (r) => r["ifName"] == "${DEVICE}")

so both sysName and ifName have identical values? and is the variable capitalized in it’s setup?

Sorry, wrong variable:

|> filter(fn: (r) => r["ifName"] == "${INTERFACE}}")

however the returned error is the following:

invalid: error @8:10-8:22: undefined identifier dataReturned error @14:9-14:21: undefined identifier dataReturned

@andrea86

Did you intend to have two right hand curly braces?

image

No, sorry. Just one right hand curly brace

Do you still get an error message?

can you show us how you set up your variables? screen shot

Working query A and B with only Grafana variables:

InfluxDB + Grafana variables, query not working:

Working single query with only InfluxDB variables:
image

that is your queries which you already have showed us. I Am asking about the variables screen where you set up the variables

typo?
image

1 Like

1 Like

Sorry, stupidly I didn’t notice