Using Transforms in Grafana to Clean Up the Legend | Quisitive
General Quisitive gradient background
Using Transforms in Grafana to Clean Up the Legend
January 14, 2025
Cameron Fuller
Use these helpful tips to easily clean up the legend in Grafana.
Blog Feature Image Using Transforms in Grafana to Clean Up the Legend

So, you are using Grafana to show off a bunch of interesting data you have in Log Analytics. You build up a Kusto query (like the one below that shows % CPU utilization averaged per hour).

InsightsMetrics
| where Namespace == "Processor" and Name == "UtilizationPercentage"
| extend Computer = iff(Computer == split(Computer, ".")[0], Computer, split(Computer, ".")[0])
| summarize avg(Val) by Computer, bin(TimeGenerated, 1h)
| project-rename Avg=avg_Val
| project Computer, TimeGenerated, Avg
| where Computer in ($Computers)
| sort by TimeGenerated asc

But when it shows the legend, it looks a little like this…

Using transforms in Grafana to clean up the legend Blog Image 1: Example of the code's effects on the legend

It’s prepending “Avg “ to the start of each server name. That makes the legend much less readable. So, how do we remove that? Welcome to the wonderful world of Transforms!

You can create a Transform in Grafana to perform a variety of tasks. In this case, we will be using the “Rename fields by Regex” feature.

Using transforms in Grafana to clean up the legend Blog Image 2: Rename fields by Regex feature

The text I am using is:

/Avg (.*)/

$1

And here’s the result!

Using transforms in Grafana to clean up the legend Blog Image 3: Example of legend after Transform is applied with "rename fields by RegEx" in Grafana

Summary: Little changes like this can make a dashboard much more readable. So, if you have stuff in your legend that isn’t needed, try out the “Rename fields by Rexeg” feature!