grafanagrafana-variablegrafana-templating

Using regexp with groups in Grafana


I have Grafana dashboards with “Stat” components and I try to change the display names. I’ve found only one working way: add a field override using regexp. All works, but I can’t use groups in regexp. I want to do something like:

My_own_metric_(.+_.+) -> $1

I’ve tried a lot of different way to write it: $1, \1, ${“\1”},.. But I was only able to change it on static text.

I’m using Grafana-8.3.3-Ubuntu version.

Maybe someone knows a solution?


Solution

  • Apparently it's not possible to use groups in field override. What you need to do is add an "operation" in the query itself:

    + Operations > Functions > Label replace

    and set the legend:

    Options > Legend > Custom > {{yourlabel}}.

    So, an example for a straightforward mqtt exporter query, changing the displayed label from $SYS/broker/clients/maximum to maximum: