Rename legend by extracting key-value [Grafana + Promtheus]

Grafana v9.3.6(978237e7cb)

I’m trying to rename label by extracting legend’s key-value. Searching the forum gives me Relabeling the legend in Grafana and Rename by regexp and thought the regexp one might fit me because these label are dynamic changing and overwrite needs to be done for every legend manually I guess.

Here’s my demo:

{__name__="log", cloud="SOME_CLOUD", instance="SOME_INSTANCE", job="log", key="SOME_KEY", log_stream="SOME_STREAM", sql="SOME_SQL_QUERY"}

As you can see, my legend are super long and verbose(And when my mouse hover on the graph, no matter Line Graph or Bar Graph or Pie Graph, that legend will be so long that i can’t read it clear). How can I simpify it to the specify value of a json key?

For example, I want the legend only contains key="SOME_KEY" or even better, only SOME_KEY. I tried the Rename by regexp in Transform, but nothing changed while online regexp validator says it’s validate.

Due to new user can only embed two media file, I post my regexp expression below:

Did I choose the wrong method? I think if the legend is a json data, it should be easy to extract and replace, I tried Extract fields in Transform as well, but it seems to needs to be configure for every legend manually like Overwrite. Or did I write the wrong regexp expression?

Hi @callmeddx,

You should match whole line with .* (i.e match everything before and after string you want to extract).

Try this:



Best regards,

Ohhhh, my bad! This synatx IS explained in that regexp method post, I didn’t pay attention to it! Thanks!