OSS v2 Failing to Create a dynamic dashboard variable for the hostname found in the data telegraf scrapes

Aim: to create a variable (drop down list) of each containers host name form the host file in the data of the containers bucket similar to how this bit of code works for the buckets.

Using code below I get a list of buckets that I can use in the dashboards

    buckets()
      |> filter(fn: (r) => r.name !~ /^_/)
      |> rename(columns: {name: "_value"})
      |> keep(columns: ["_value"])

This is my code that produces the right type of results when exploring the data as a table, although i am confused by the group by and unique as they don’t do what I would expect them to. Also the variable is never populated. when used in a dashboard the value is always ‘No Value’

from(bucket: v.bucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> keep(columns: ["host"])
  |> group(columns: ["host"])
  |> unique(column: "host")
  |> rename(columns: {"host": "_value"})

it took me too long to work this out.

from(bucket: v.bucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> keep(columns: ["host"])
  |> group()
  |> rename(columns: {"host": "_value"})

Explanation
1st line gets data from the bucket of my dash variable for bucket.
2nd line limits the time range (all queries need a time range filter)
3rd only keep the host column
4th group (with no column specified unlike sql)
5th rename the column to _value special key for variable assignment.

1 Like