Reputation: 3
I am trying to make a dashboard in Grafana, where all the variables are defined in the dashboard settings. Most of these are constants, though I have three input variables in the dashboard that will reactively change several other variables. My issue is that I am unable to define new variables that will reactively change depending on the value of input values.
For instance, suppose I have defined an input variable "input1" that is set to 10. I want to make a new variable "test" = $input1 * 10. When I attempt to do this, I get that test = "$input1 * 10" rather than test = 100.
Even when I use any two constants, eg. "a" = 10 and "b" = 2, if I try to make a new variable "c" = $a*$b, I get that c = "$a*$b" rather than c = 20.
Is there a way to perform calculations like these when defining variables? I am not querying or extracting data from any external data sources - all variables are defined in the dashboard settings.
Upvotes: 0
Views: 2034
Reputation: 28716
Grafana can't evaluate calculation of variables. But you can do that in used datasource.
Switch variable to Query
type and write query, which will be executed by selected datasource and it will return calculated value.
Example for PostgreSQL
type datasource:
SELECT $a*$b
Of course not all datasource types can perform this kind of calculations. SQL datasources can do that usually.
Upvotes: 1