Hi ,
I am using grafana 10.3.3
I have a panel where I want to dynamically update the unit for the displayed metric based on drop-down selection
How to achieve this?
Any pointers?
Thanks,
Nilanjan
Hi ,
I am using grafana 10.3.3
I have a panel where I want to dynamically update the unit for the displayed metric based on drop-down selection
How to achieve this?
Any pointers?
Thanks,
Nilanjan
Hi,
You could do something like this:
Create a query using Infinity Plugin
that will be of type inline CSV with backend parser. In there, type in the list of metrics you have and the units you want the metrics to have (like in the screen below). In Computed columns, Filter, Group by
toggle, go to Filter
card and insert contains("${metric}", metric)
(assuming your variable is called metric
- if not, act accordingly).
Create a second query using the datasource of your choice (to mix datasources used -- Mixed --
datasource.
Go to Transform data
tab and use Config from query results
transformation. Select the infinity plugin query as the Config query
, apply to desired fields (e.g. second screenshot). If you named your column with units unit
Grafana will set the unit automatically, if not, select Unit
from dropdown.
Should work. If you’re not sure which units to use, you can select the desired one, go to JSON model and there will be the name of the unit.
We have to do it that way because for now Grafana doesn’t resolve variables in unit picker.
Hope that helps!
Hi ,
I tried this option …but did not work out for me.
For me the requirement is as below -
I have a drop-down from which I select a single metric.
I have a panel . which would fetch the data from the back end via a REST call and show the data as a time series graph in the panel.
My requirement is to dynamically show the corresponding unit also in the panel based on the metric selection.
Any alternative approach is possible in Grafana ?
Thanks,
Nilanjan
Can you provide some more screenshots, etc? How Grafana should know which metric corresponds to which unit? Is the list of metric static? What do you mean by “corresponding” unit?
If your API returns something like:
{
"unit": "ms",
"data": [
{
"time": "2024-12-31",
"value": 1
},
{
"time": "2024-12-30",
"value": 1
},
{
"time": "2024-12-29",
"value": 1
}
]
}
could you do two calls in two separate queries and then go with my original answer (after parsing it)?
Another way would be to have a chained variable that would query the unit for the metric, but you would still need to go with my original answer, since Grafana does not support variables in unit field.
Please provide sample data and the different types of units and how these units relate to the data and the final look of the data when units are applied
Hi ,
My scenario is as below.
In the Grafana dashboard drop down , I have the following parameters -
param1, param2, param3, param4,param5
When the user selects any particular value from the drop-down, we make a REST call to the backend and fetch the data for that particular selection and display the value as a time series graph.
The REST call returns only the value and not the unit.
I maintain another CSV mapping for the parameter to unit mapping -
metric.unit
param1, Number
param2, Percent( 1- 100 )
…
…
Now , I want to display the corresponding unit for the selected parameter values in the time series graph in my Grafana panel.
The unit picker does not resolve my unit variable.
So, for the time being I am dynamically updating the panel title with the corresponding unit variable value, but my requirement is to display the unit dynamically in the timeseries graph along with the value.
How to achieve that …
Thanks,
Nilanjan
you have provided us a solution you have implemented but have not described your requirements in plain English. starting off with an existing solution would be like a code review where in we point you to issues within your implementation.
What we need from you, help us help you, is for you to provide sample data and the result you want to see in plain English not in implementation within grafana