Can I create (and use) a template variable with the actual combinations of multiple labels?

What Grafana version and what operating system are you using?

Grafana v7.3.1 (6668161a88) on Linux (official Docker image)

What are you trying to achieve?

I’m using the JMX Exporter to collect metrics from several Tomcat instances. Each instance has a different set of DB pools. I would like to have a single dashboard with all the time series for all DB pools of all instances.


  • instance foo, pool name oracle_1
  • instance foo, pool name oracle_2
  • instance bar, pool name mysql
  • instance baz, pool name oracle_1 (note, coincidentally same as above)
  • instance baz, pool name postgres

How are you trying to achieve it?

At first I tried using two template variables, one for the instances and one for the pool names, using one for the rows and the other for the inner panel, but I found out that it’s not possible.

The two distinct variables are:

  • instance: label_values(up{job='jmx'}, instance)
  • pool name: label_values(tomcat_dbpool_numactive, name)

And the way I can use them in my panel:

  • tomcat_dbpool_numactive{instance=~"$container", name=~"$name"}

But the result is a table with the outer product of all possible instances × pool names, which in my case is mostly empty (eg. there is no pool oracle_1 on bar, there is no oracle_2 on bar nor baz, etc.)

Therefore I’d like to define a single variable with the actual combinations of values for instance × pool name. For example:

  • foo:oracle_1
  • foo:oracle_2
  • bar:mysql
  • baz:oracle_1
  • baz:postgres

But I have no idea how to define such a variable, let alone how to use it in my queries.

This topic was automatically closed after 365 days. New replies are no longer allowed.