Search code examples
prometheusgrafanametrics

Grafana + Prometheus how to use regex in query metrics?


We are dynamically adding new metrics. Is it possible to use regex in Grafana query metrics?

application_test_total{color="0"}
application_test_total{color="1"}
application_test_total{color="2"}

How to avoid this?

sum(application_test_total{color="0"})+sum(application_test_total{color="1"})

Is it possible to replace with this?

application_test_total{color="[0-9]{2}"}

Solution

  • You can replace:

    sum(application_test_total{color="0"})+sum(application_test_total{color="1"})
    

    To:

    sum(application_test_total{color=~"[0-9]{1}"})