Dropdown menu in dashboards where data are coming from influxdb

  • What Grafana version and what operating system are you using?
    Grafana v9.5.0-cloud.5

  • What are you trying to achieve?
    I have various dashboards for the data coming from influxdb. I want to create the dropdown menu for the different tags in my influxdata source, so that i can select one or two or all to view the data in different tags.

  • How are you trying to achieve it?
    I am trying to achieve this using variables in dashboard settings. There are many options, among them i tried query options which didnot return my tags but returns values or nothing all the time. I am using flux query in every dashboards. So each dashboards has data for each tags in influx instead of that i want to select tag from dropwdown menu.
    I did create custom variable where i include my tags manually. now when i select the tag in the dropdown menu created using custom variable it didn’t work.

  • What happened?

  • What did you expect to happen?

If you notice the influxsb UI i am looking for similar dropdown menu where i can select different tags and visualize it in dashboads. Suppose right now in my dashboard i have data from all user with all tags, i want to select some user and some tags in that dashboard using dropdown menu. I

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

  • Did you follow any online instructions? If so, what is the URL?

Welcome @leonardoselex to the Grafana forum.

Here is how I use tag values in my dashboard using this:

Thank you much for the reply. Yes for example i got the dropdown menu suposse of my tag “projectnumber”, but i select any one of them in the dropdown menu i still see the data from all the projectnumber in the dashboards. How do i solve this? thank you much again

Continuing with my previous example, the Flux query gets modified in Grafana using ${tag_name} like this:

from(bucket: "Mydata")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_field"] == "GeneratorTemperature")
  |> filter(fn: (r) => r["MyEquipNumber"] == "${GeneratorNumber}")
  |> filter(fn: (r) => more filters....
  |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
  |> yield(name: "last")

thank you very very much. This works when i select item in a tag but the thing when i select select two poject number in a tag called projectnumber it says nodata.
How can we solve this?

Thank you much in advance

Continuing with my example, if we want to use two tag values (e.g. 301 and 303) in the same query, replace this line:

  |> filter(fn: (r) => r["MyEquipNumber"] == "${GeneratorNumber}")

with this:

  |> filter(fn: (r) => contains(value: r["MyEquipNumber"], set: ${GeneratorNumber:json}))

However, you may have issues with the legend and may need to create some overrides or transformations.

thank you yes it works.

May be there was bit problem with loading the dashboard as soon as i configure the variables i made in the current dashboard.
Other dashboard without the use of the variable are loaded fine but with this its really slow.

Is there any effect of it ? any idea?

Apparently contains() can cause performance / speed issues. Maybe check this out and try it and report back here if you get it to work better.

contains() function is way to slow! If performance is an Issue, I recommend avoiding it at all costs.

what I do, is I build entirely the “filter” piece of the code, using another chained variable that makes another query using Variable1, then with reduce function and some trickery I reduce all my “selected values” to one single string.

then in my main query I use the “filter” like this:

|> filter(fn: (r) => ${Variable2})

Note, I cannot give a general piece of code because it is kind of specific to your data set, and you may need to add some “dummy” values in case the query returns a “null” string because.
|> filter(fn: (r) => ) will get you an error

Just curious as now this post seems more fitting for the InfluXDB category.

Please let me know if it OK to move it there…? :slight_smile:

Yes, InfluxDB is the better category for this post.

I have adjusted:

1 Like