user2084865
user2084865

Reputation: 697

How to nest variables in grafana?

I have a simple Custom variable called route with e.g. this value:

/foo/bar,/foo/baz,/foo/baz/foo

I'm trying to map these values to some more understandable values, e.g. Custom route_names:

bar,baz,foo

Searching on google resulted in people doing nested variables, but whatever I try in Grafana 5.3.4, I can't get it to work. If I do a Query variable and use -- Grafana -- as source, I don't know what to put in the query field. route.* didn't do anything, $route neither.

What is the correct way of selecting a value from one variable and map it to the other? I.e. What is the query language being used when selecting -- Grafana -- as datasource?

As a side note, I have two datasources at the moment, my actual data source where I get my graph data from and -- Grafana --.

Upvotes: 2

Views: 5960

Answers (2)

istend
istend

Reputation: 21

There are correct answers on the first floor. solve "key/value pairs" by SELECT 'txt1' AS __text, 'value1' AS __value UNION SELECT 'txt2' AS __text, 'value2' AS __value

Upvotes: 2

Yuri Lachin
Yuri Lachin

Reputation: 1500

This is not possible with Custom template variables (unless smth changed in recent Grafana versions). It can be done with variables coming from mysql, postgres and clickhouse datasource queries. See examples in https://community.grafana.com/t/key-value-style-for-custom-template-variable-configuration-and-usage/3109 thread. Can't tell about this feature support in other datasource types.

Upvotes: 0

Related Questions