Use custom variable key in queries

  • What Grafana version and what operating system are you using?
    grafana:7.4.0 inside k8s Cluster (v1.18.17-gke.1901)
  • What are you trying to achieve?
    we have below metrics from prometheus:
operations_aws_provisioning_succeeded_total
upgrade_cluster_result{plan_id="1111"}

operations_azure_provisioning_succeeded_total
upgrade_cluster_result{plan_id="2222"}

We would like to have one custom variable with values:

e.g. variable: plan_id with values aws : 1111, azure : 2222

And created query template using above custom variable

upgrade_cluster_result{plan_id="$plan_id"}
operations_${plan_id.key}_provisioning_succeeded_total
  • How are you trying to achieve it?
    Am trying to obtain customer variable’s key inside a query expression
    operations_${plan_id.key}_provisioning_succeeded_total

  • What happened?
    Didn’t find a way to obtain the key for a custom variable in key : value pairs formate inside a query expression

variable: plan_id with values aws : 1111, azure : 2222

How can we get the variable keys (aws, azure) inside a query expression

  • What did you expect to happen?

  • Can you copy/paste the configuration(s) that you are having problems with?

  • 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?
    Add a custom variable | Grafana Labs