Query breaks when host variable is used

I am trying to create a panel to show the temps of a switch.

The switch sends those temps as Celsius, I want to show them as Farenheit.

The query to get the metric works fine, even with a host variable. That query is “A”.

Then I create an expression to recalculate the Celsius value to Fahrenheit:
Simple expression: $A * 1.8 + 32

The second I add the expression and include the query variable $A the data panel goes to NO Data, and I get an error flag: 2 items dropped from union(s): [“$A * 1.8”: (1.8: {}][“$A * 1.8 + 32”: {})]

If I use the actual host name instead of a variable, I have NO problem everything works fine. I could create a copy of the dashboard for every device, but I would rather just use a host selection dropdown so we maintain one dashboard instead of many.

The picture above shows the panel. There are three temps, the top value is not working because of the host variable being used in query “A”. The same would happen to the other two values if I used the variable in their queries (C and E)

I feel like I must be missing something basic… I cannot believe that this product would not be able to include/pass a host variable in its queries?

Can anyone offer a solution?

1 Like

It may looks simple, but it is not, because you are missing time dimension (it is query result, which may be timeseries with multiple values):

Thanks. But the query itself is not the issue… It is the fact that it breaks when a Hostname variable is introduced into query “A” AND an Expression (“B”) is added to recalculate the value of “A” If I use the actual Hostname (not a variable), it works fine. If I change the host name to a variable the query gets broken when an expression (“B”) is added.

Yes, first sort query A (so remove/disable expression, which is misleading error here, because that’s just consequence of query A error)
Use query inpector and make sure that variable generates proper syntax with right variable formatting: Variable syntax | Grafana documentation

Perhaps you can try to perform this conversion from Celsius to Fahrenheit in Zabbix, using a calculated item, then consume this item in the Grafana panel.

This step would be simpler and faster, leaving all the calculations on Zabbix’s side and just visualization in Grafana.


Thank you. This is just ONE example. The problem is not in the calculation, since the calculation works until a Hostname variable is introduced. It is with how Grafana uses it’s own variables in queries, expressions, and layers. Maybe this is specific to the Zabbix plugin? This is key to templating dashboards. It not only affects calculations, but whether the same dashboard item can work across multiple devices.


How are you using the variable in your query

I spoke with the good folks at Grafana this morning and showed them my problem.

They agreed that what I am doing should (in theory) work.

They are going to talk amongst themselves and see if they can come up with a solution. I will post back here after I hear from them.


It’s not really wrong, this way it should work, if you need a faster solution, try doing it using Zabbix or even using Gratana’s transform function

I have same issue msulewski, has it been resolved?

Our group and Grafana are meeting up next week. I will post back if we have a solution.

Met with Grafana. It is a confirmed issue at this point that the Zabbix plugin does not parse the Host variable in Grafana.

They are escalating to see if they can come up with a fix.

We did come up with a work around.

1: Remove any expressions.
2: Create a new Panel, Select “Dashboard” as the data source.
Select the dashboard that has your queries that were having the problem.
It will show you all the queries from that dashboard.

You can now do transformations on those queries.

in my case I had to do two transformations on each query to get the calculation I was trying to do (Query result * 1.8 + 32).

In the first item I had to select the first query, the operator (*), and the value (1.8).
I had to give it a unique alias that would then be used in the next step.

Second step select the first query again, the Operator (+), and the value (32).
Give this another alias (This would be the final number).

To keep each number together, I had to apply a filter selecting the corresponding query, and make sure that Replace all Fields was selected. Then I could apply colors, thresholds and everything else.

The old panel I had to set the items to transparent and then just shrink it down so it was not the focus on my main screen. (There is no way to hide a panel you do not want to see).

1 Like

thank you msulewski for your response

What is your version grafana msulewski,I have latest version (10.3.1) but I didn’t have this option

this my panel

thank you a lot

I am on Open Source version 10.2.3

Any information if this has any relation between wide and single series data? For another similar reason I asked for a issue on Transformations: Reduce with reduce fields don't work with wide-timeseries dataframes · Issue #71303 · grafana/grafana · GitHub and I was answered with a WAI that I don’t agree… Maybe if it’s a similar reason, it could help.

I remember that there’s some data from zabbix that grafana transforms to Wide series, and some data that goes as Single Series… Causes some trouble when transforming data.

1 Like