Using the Value of a Template Variable to Select Another Value

  • What Grafana version and what operating system are you using? 8.1.2

  • What are you trying to achieve?
    I have a template constant that indicates which environment is being used. I will have dashboards set up in 3 different environments so the value of the environment variable will change can have the following values:

dev, int, prod

The Apis I am monitoring will have different domain names based on the environment selected.
For example, in Dev the domain name would contain “.m2d”, in Int is would be “.m2i”, and prod would be “.m2p”.

So when the value of the environment value is Dev, I would like to have another variable the will pick the right domain name subset.

If environment = “dev” then return “m2d”
if environment = “int” then return “mdi”

  • How are you trying to achieve it?
    I’ve attempted to work with template variables to achieve this. The “Custom” variable seems like the best match because it apparently lets you map values and return a different value. But I can’t get it work because the value I am using is a variable.

This is idea of the mapping I’m looking for:
($Environment.value==“dev”:“m2d”,$Environment.value==“int”:"m2i…)

  • What happened?
    I cannot get it to work.

  • What did you expect to happen?
    I expect to be able to pass in a variable to another template variable and have it return a value based on the value of the variable passed in.

  • Can you copy/paste the configuration(s) that you are having problems with?
    This isn’t a configuration issue.

  • 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?
    Templates and variables | Grafana Labs

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