Changing infinity datasource in a dashboard based on variables

  • What Grafana version and what operating system are you using?
    Grafana v11.3.1 (9225f4a1cb) running on Ubuntu 22.04 VM

  • What are you trying to achieve?
    Use different infinity datasource based on a dashboard variable.

  • How are you trying to achieve it?
    I have a dashboard variable named source. It is populated based on a query which selects the available layer-2 switches which emit telemetry data. Sample variable value can be switch1, switch2 etc.

Corresponding to the two switches (mentioned above) I have 2 inifinity datasource setup. The dashboard is expected to display telemetry data for the switch indicated in the source variable when used as a query key in appropriate fluxv2 queries. An example snapshot can be seen below.

One of the (library) panels uses infinity datasource. I’d like to change this datasource based on source variable such that changing source e.g. from switch1 to switch2 will change to the corresponding infinity datasource so that appropriate information pertinent to that switch can be represented.

Hi,

Is your source variable a part of the name of the inifnity datasource (like e.g. your source variable values are switch1 and switch2 and your infinity datasources are named infinity-switch1 and infinity-switch2)?

Anyway, here’s what you could do:

  1. You need to create some kind of mapping from your source variable to your target infinity_datasource variable.
    1.1 If your infinity datasources contain the switch names, you don’t have to do that step.
    1.2 If your infinity datasource are not connected in any way with switches, create a via variable (or any other name - it doesn’t really matter) of type Query, show nothing on dashboard (for tests you can of course show everything), use Infinity Query Type and inline csv. In there, type the names of your switches and your datasources. The trick is to use filter (Computed columns, Filter, Group by toggle) to limit this variable to only the one of source variable value (refer to the screenshot).

  2. Create datasource variable.
    2.1 If your infinity datasources contain the switch names, you can just create the datasource variable of type infinity and in Instance name filter type /.*$source.*/ regex - it will limit the datasources to only those that contain the switch name.
    2.1 If not, do the same as step one, but use $via variable (or whatever you named it) - /.*$via.*/ as regex - result should be the same but more generic.

Limitations - only one to one matching - you won’t be able (probably I’ve never tested it) select two sources and select two datasources at the same time. Also, only one datasource should match to one source.

Hope that helps!

1 Like

Create a datasource based variable

Select variable type Data Source
then Data source options → Infinity

in the dashboard

in the datasource

1 Like

Thank you @dawiddebowski and @yosiasz . You guys are amazing!
@dawiddebowski : 1st option fit my use-case as I could easily change the infinity datasource name to include results from the ${source} (as seen by screen shot below)
@yosiasz: Thank you so much for the screenshots. Those were very helpful in solving my case. I’d love to have picked your proposal as the solution as well. Unfortunately, the GUI doesn’t let me select two solutions.

image

1 Like