Implementing percent_diff() in the Influxdb query

Hi. I’ve created a dashboard for my HPE server’s iLO data which I receive by querying its SNMP OIDs using Telegraf as my data-collector and Influxdb as my data-source.
Previously, I’ve set an alert for power-meter so that if the server’s power consumption in the last 24 hours or the past 1 hour had more than 50 percent growth or fall, I’d get a notification; and I set that alert condition using percent_diff() function as you can see in the below picture.

It works completely fine, but the issue here is that I want to remove this alert condition and instead, implement it through a query on the data-source and have it displayed as a time-series which shows the percentage of rise and fall of the data in the past 24 hours for each data-point; but I haven’t been able to do that yet, since that percent difference function isn’t available on the query panel.

I’d appreciate it if you could help me with the possible queries.

Here’s the regarding panel and it’s query:

Thank you in advance.

  • What Grafana version and what operating system are you using?
    Grafana v8.3.6 (self-hosted)
    Debian 10 as Grafana’s host VM

To be more specific, I need this formula to be displayed on the graph:

(((powermeter_current_reading).now - (powermeter_current_reading).now-1h) / (powermeter_current_reading).now) * 100

Welcome to the forum.

I think you will need to add a new query (“B”), click the pencil icon, and write the query from scratch. I do not think it is very hard.

I have a query where I compare the setpoint vs the actual and set the alert condition based on that difference. Here is what it looks like:

SELECT mean("FurnacePresentValue") - mean("FurnaceSetPoint") AS "FurnaceDiff" FROM "stations" WHERE $timeFilter GROUP BY time($__interval) fill(null)

Hi, and thank you for your your response.

I know how to do the math, but my actual problem is how to select the data in a specific point of time, as I mentioned in my second comment.

For example, I want the this data to be displayed on my graph:

At 8:30 → show the value of [data_at_8:30] - [data_at_7:30]

At 8:31 → show the value of [data_at_8:31] - [data_at_7:31]

If you write your query as you describe (let’s call it “B”), and display it on the same graph, then does it appear as you wish? If not, what does it look like?

Could you please guide me through how to select a setpoint as you call it?

SELECT last("powermeter_current_reading") - last("powermeter_current_reading") AS "Difference" FROM "ilo_snmp_esxi" WHERE $timeFilter GROUP BY time($__interval) fill(null)

In the query above, I can get the power.Now by using last() function, but my problem is that I don’t know how to select the power.Now-1h.

Could you help me with this?

Hi @marjan.mesgarani My query example was calculating the difference between two values (actual & setpoint) taken at the same timestamp. Looking back at your desired calculation, it’s a bit tougher because it involves the timestamp from 1 hour ago. I did a brief search on this and while it may be possible in InfluxQL, upgrading your InfluxDB to 2.0 (or higher) and using Flux will make this a very straightforward query. See more here.