Rename values by regex?

  • What Grafana version and what operating system are you using?
    Grafana Cloud

  • What are you trying to achieve?
    I have a state timeline like this, which shows each value as a number. I want to value map those numbers to textual labels. I have this text available in a separate query, but in a slightly different format.

  • How are you trying to achieve it?
    I added another query (called config) with “organize fields by name” which produces a table like this, with 2 columns for port number and port_name. Then I add a “config from query results” with “value mapping / value” and “value mapping / display text”.

  • What happened?
    It doesn’t work because the port number column in my config query is prefixed with the letter I. So I tried adding a “rename fields by regex” to remove that I, but this doesn’t work, it just renames the column name.

  • What did you expect to happen?
    I thought “rename by regex” would strip the I from the beginning of each port value.

To mock this up, I used an Infinity query with inline CSV data like this:

port,port_name
1,Mac HDMI
2,LVO
3,Apple TV
4,None
5,Google Meet
6,Roku
7,HDMI Present
8,None

With this, the “config from query results” transformation works correctly to make the value mapping look like this:

So I’m just struggling to figure out how to turn a value like I1 into 1. By the way the data comes from Prometheus.

Your value from prometheus is I1? Or is it a label value. If it’s the label value, you can use label_replace function which would look something like this:

label_replace(<your_query>, "<label_name>", $1, "<original_label_name>", "I(.*)")
1 Like

Perfect, thank you!

1 Like