Use a custom-variable in a custom-variable

Hello everybody,
how can i use a custom-variable in a custom variable?
I can’t find syntax. I’ve tried everything possible but unfortunately without success.
Is it even possible?

You can learn more about custom variables in our documentation:

Hello @ivanahuckova, thank you.
I have already read this documentation :slight_smile:

It says the following
ou can include numbers, strings, *other variables

Do you have examples of using other variables in custom variables?
Which other variables are they, custom, query or constant?

Is that possible?

cust1

cust2

Sorry @ivanahuckova but the documentation for variables is really lacking. Before posting a RTFM reply you might consider the question “does the documentation actually answer the question?” There are very few examples and the documentation tends to be very high-level.

1 Like

I the same need for nested custom variables as I need to group servers in a custom way that our company’s structure does not allow in Graphite.

We have different services on our platform and I would like to be able to select one service on my dashboard and then have all my panels show the data from all the servers associated to that service only

@ivanahuckova are you saying that nested custom variables are possible? The documentation is really thin and I cannot find a way to achieve this.
Also the function of key : value pairs is not clear to me. What can they be used for?

@stofi You are right, I should have elaborated more. Custom variables don’t support chained variables. As documentation says, Chained variable queries are different for every data source, but the premise is the same for all. You can use chained variable queries in any **data source** that allows them. Interpolating of variables happens in directly in the data source. And Custom variables don’t support that.

I have quickly checked the feature request on github and haven’t found this as feature request. If you think that this could be useful, please open the issue in github feature request and tell us about your usecase and why would it be useful. :slightly_smiling_face:Or if you have different idea how to solve your issue with Graphite, please share that.

Regarding key : value pairs. It is a way, how you can give a name (label) to your value. Couple of examples - you want to name days in your native language, but want to pass english value to the query. Or you want to give label name tracing (so everyone knows it is tracing), but the value is the name of actual tracing backend (tempo). See bellow:


thank you @ivanahuckova for the details. I finally got around to try out the key : value pairs, but struggle to get it to work. Somehow my key value pair seems not to get recognized as in the preview of values I see both values and, subsequently, in the query inspector I also see key and value.
Grafana version is 7.2.0
Any idea what I do wrong?
Also would this syntax be valid as well: key : {value1,value2, value…}?
This way I could create collections for server names and give them a name for easy selection


The functionality was added in 7.3.0-beta1 release. So you need to upgrade to at least that.

1 Like

Thank you for the quick reply

1 Like

I’m not sure if you know this or not, but when defining the key-value pairs you have to use a space before and after the “:”. It’s counter-intuitive that you’d have to use spaces, but it is called out in the documentation on Custom variables.

For instance:
This won’t work: key1:value1
But this will: key1 : value1

1 Like

Is there a way to use the key in your panels, or just the value? My use case is I want the panel title to include the variable label, not the variable value.

2 Likes

Suppose the variable is TheVariable and is defined as:
name1 : value1,name2 : value2

You can use ${TheVariable:text}

Is there any example of using these variables within variables? Specifically with a many to many relationship?

Variables
map1: key1 : value1,key2 : value2
map2: key3 : value3, key4 : value4
mapOfMaps: map1Key : ${map1:value},map2Key : ${map2:value}

Ex if I select map1Key, it will reduce key1, key2 return those values according to selection.

Hi @stofi,

Regarding your question:

Also would this syntax be valid as well: key : {value1,value2, value…}?
This way I could create collections for server names and give them a name for easy selection

If this is still relevant, you may find the following helpful:

Good luck!

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