I am using Grafana v8.4.10 on a Linux instance.
I have an InfluxDB datasource configured with query type as InfluxQL.
I have a list of devices for which timeseries property data is captured in influxDB.
So the property data is stored into separate measurement table for each device.
I want to display the data for all the devices at the same time in a timeseries chart.
So I have all the device list queried and stored into a variable. And to show the property data for all the devices in the chart, I am using influxDB query as below.
SELECT “time”, “propertyName” FROM /($Variable)/
This will return the property data for all the measurements (i.e. devices) together and display on the chart.
But the problem I have is the chart legend is showing each plotting in graph in format as below.
Device1.propertyName
Device2.propertyName
Device3.propertyName and so on.
Whereas I want to display it as
Device1
Device2
Device3 and so on.
How can I achieve custom column name in the query I am using to show only the measurement name as legend or column name instead of measurement.propertyName which is appearing currently.
I am hoping we can achieve this with regex, but I am not sure how to do this.
Or if there is any other way possible.
SELECT “time”, “propertyName” AS “” FROM /($Variable)/
This did not work if i give empty string.
If i give a single space in the alias, it removes the property name but the dot does not get removed and I get “Device.” Instead of getting just “Device”
As my dashboard panels are bigger in size that dot does not look good.
Also I tried as per what you suggested.
SELECT “time”, “propertyName” AS metric FROM /($Variable)/
Using this, I am seeing output as
Device1.metric
Device2.metric and so on.
Meaning, the property name got replaced by the metric word.
Please share if you something specific related to aliasing.
If someone is looking for answer. try this
You have to use “Rename by Regex” in Transform tab(next to query) where you can match and replace in it. Example below.
Match : /.propertyName./
Replace: (give a space here)
In case someone would like to customize field name for different variables (repeat options) AND your data source allows including identifier to your field:
In my case, I was querying PRTG for Disk Free Space %, repeated by VM. I wanted to hardcode the drive name as field name. So…
I enabled an option on PRTG query to include device name and rename each field on case-by-case basis:
To apply for all VM
Match “.*.Free Space C:” to be replaced by “System (C:)”
To apply for specific disk on specific VM
Match “PCname1: Free Space D:” to be replaced by “Data1 (D:)”
Match “PCname2: Free Space D:” to be replaced by “Local Disk (D:)”
It depends on your schema, it may not be the most optimal solution, but it was my easy way out…