I want to remove a string from the legend format in Grafana

I want to remove _custom_exporter from all the metrics being present on the Grafana dashboard.

How do i put this in legend format?

i should display only OS names.
like ubuntu20_04 instead of ubuntu20_04_custom_exporter.

Can you please help me?

Hi @murarisaranvikas, welcome to the community!

This post in the community has a lot of great information about how to use the value mapping feature with regex to edit values that show up in your graph.

I think we could definitely use more examples, so I mocked up your query with CSV data and
a bar chart to show an example of how you could remove the end of the value name in your bar chart.

To transform this:

Into this, removing the _exporter string at the end:

You can use a value mapping in the bar gauge options in the sidebar of the panel editor.

When you click Add value mappings it opens with a default Value mapping not Regex.

Click the Add a value mapping button, and choose Regex from the dropdown to add the regex value mappng and substitution. You can delete the default value mapping.

The regex (.*)_.* will capture everything up to the last underscore and $1 will substitute that as the new value.

The site https://regex101.com/ is a really helpful tool to test out regex. You’ll want to change the flavor to golang to get the right interpretations for Grafana.

1 Like