I have some measurements in InfluxDB that I am trying to graph with Grafana. There is a Tag called “friendly_name”, which is in the format:
friendly_name = RHT Sensor (***)
where *** can vary (i.e. Kitchen, Bedroom, etc).
I am using GROUP BY(friendly_name) in the query, which gives the following:
The problem is that I want to rename the legend entries automatically to just show the room name (i.e.Kitchen, Lounge, and Main Bedroom, in this example). How can I do this?
If I just add $tag_friendly_name to the Alias field, then it doesn’t quite work:
Yes, I tried to choose “Fields with name” set to “value”, because every single one of my data have a field called “value”, and so I chose this because I want to override the display name of all traces. Then I tried some kind of regex in the display name box, but I think I am barking up the wrong tree, and don’t really understand it… sorry, I have never used regex!
Hi @ppxtb,
In Transform tab (near Query) you can choose Rename by regex and for Match enter:
.*\(([^\)]+).*
and leave Replace as $1.
Regex breakdown:
.* - means any symbol 0 or more times (basically means match anything)
\( - specifies that after anything there must be a literal symbol (
( - starts matching group
[^)]+ - means match anything until you find ) symbol
) - closes matching group
.* - matches anything till the end
Replace breakdown
$1 - means return what you matched in first group (in this example only 1 group exists)
For checking regex I suggest regex101 site because there you can see what you matched with regex (marked in colors) and explanations. Few days ago I read that Grafana uses Golang flavor of regex so be sure to click on that on left menu:
The main difference is that with “Transform → Rename” you are using regex to match specific part of time series name (in your example you were matching part of friendly_name tag) for all queries (A,B,C… - you only have one) you have in panel, while in “Override → Display Name” you are using regex to match specific fields to which you will apply property override (in this case that is Display Name). Display Name option does not support regex (they would be interpreted as literal symbols as you show us on post 5).
Display name option is useful for example if you are using InfluxDB with Flux language (v 2.x) and you want to change field name to value of specific tag ( for example to change field name to value of host tag use ${__field.labels.host} ). That would act same as ALIAS BY = $tag_host in Influx QL (v.1x)
thanks for the answer, but it still does not work. I don’t know if it is because I am using LOKI as data source, it seems that the problem is in the “space” character and the “:” character. I solved it with this regex