0

Grafana version - v7.5.3

I have two “custom” variables -

env - has following values: test,prod

instanceidtest - someid

instanceidprod - anotherid

JSON example:

“targets”: [

    {

      "alias": "cpu",

      "dimensions": {

        "InstanceId": "$instanceid${env}"

      },

I want to template variable in another variable something like this - $instanceid${env} to become $instancetest

1 Answers1

2

Create just one custom variable called "env" like the following:

Values: test: someid,prod: anotherid

Note: the spaces are important

To get the id accordingly with the selected env use: ${env:value}

See this answer for more details.

  • It works, thanks a lot. But I've faced another issue - how to get the name the variable if we will use `test: someid,prod: anotherid` type of the var definition? Because some panels point to the `test` or `prod` word in a query, e.g. - `jvm_memory_total_used_mb{exported_job="api-$env"}` – Adil Idrissov Mar 30 '22 at 06:54
  • Great. Could you then accept the answer? To get the key of the variable use: ${env:text} – Marcelo Ávila de Oliveira Mar 30 '22 at 15:06