Help With Dynamic Unit Changing

Grafana v10.4.2 Linux Ubuntu 22.04.4

I have a dashboard for measuring 2 PDUs with snmp metrics from snmp_exporter. I am trying to display a gauge panel for device load in kilowatts from the rPDUIdentDevicePowerWatts metric:

Screenshot 2024-09-20 at 9.35.40 AM

I do a transformation where I take the value and divide it by 1000 so I can get kilowatts:

Here are my other configs for the gauge such as the query, unit I set, and thresholds for color:

My issue is that out of the 2 PDU’s only one is coming back with the correct conversion in kilowatts, the other one for some reason the transformation for dividing by 1000 to get it into kilowatts does nothing and it is showing as watts:

Even though the configs for both are the same panel where I just toggle the instance/IP number. I cannot seem to figure out why one works and the other does not. I have tried deleting the panel and creating a new one but it gives me the same issue. I even tried setting the initial unit as Watts so after the transformation it would convert to kiloWatts, but same thing, one of my PDU’s seemingly ignores the transformation and just stays in Watts.

Update: If I change the transformation on just this instance giving me the wrong unit (now megaWatts ?!?!) to ‘+ 1000’ rather than ‘/ 1000’ I get the correct display, however it does not use my correct thresholds now:


Hi,
I think Grafana is working as expected, let me tell you why I think that.
In your transformation, you’re calculating the value of kW and then, you’re telling Grafana “my value is in kilowatts”. Grafana then thinks “ok, so your value is in kilowatts, so if I get value of 0.8 kW, then it’s 800 W and it’s better readable than 0.8 kW. I can even show it better (if it’s something like 842.13 W)”. The kW you set in the transformation is the name of the series, not the unit, for Grafana it only means that your series is named that. It could be named “my awesome watts” and Grafana cannot infer meaning from that. If I were you, I’d let Grafana pick my desired prefix to the unit (and get rid of the transformation, since you’ll be using Watts and the unit should be Watts). My reasoning: if you had very little Watts, then Grafana automatically would change it to mW or (if very much) kW or even MW.

On the side note, I think mW refers to miniWatts / milliWatts (the second one sounds better :sweat_smile:).

As for the thresholds - look at the raw value you’re providing, the thresholds are unitless (you can toggle table view, which I find really useful whenever I play with transformations). Most probably your value 1.88 kW is 1880 Watt, which is much more than 1.9 Watt you’ve set in the threshold.

HOWEVER

If you insist on keeping your unit to kW (which I do not recommend for the reasons provided above), I think there’s a workaround (yet it isn’t pretty). You can keep your transformation, then (depending on your datasource but I guess it’s Prometheus / Influx), add transformation Organize fields by name and toggle visibility of all other fields (so only kW is left seen). In your gauge set Value Options => Fields to All Fields and Standard Options => Display Name set to ${__series.name} (this will display kW under the gauge). As I said it’s more of a workaround and I’d really recommend using proper units in Grafana. Anyway, end result would look something like this (without thresholds):
image

Ain’t pretty but shows kW and will always show it, no matter the value.

Thanks for the answer and workarounds. I am building this dashboard based on metrics already being monitored and to keep consistency I want the metric to remain in kW. Keeping it as Watts would be the easiest solution, but again building this for someone else I did not want to change the metrics and units they are used to.

I was able to just create a custom unit called ‘kW’ that allowed my computation to still work and show a kW after the amount to achieve my desired results.