user3466413
user3466413

Reputation: 819

How do I use cumulative data to show an hourly total?

I'm logging data from my gas meter using rtlamr to InfluxDB 1.6.7. The gas meter periodically transmits its consumption in a running total, so it looks like this (for example):

100
100
101
101
102
105
105

It doesn't transmit at a fixed time interval. It just occasionally chooses to emit a value usually every few minutes.

When plotting this data in Grafana, how can I instead see total consumption grouped by hour rather than an ever-increasing running total? I've seen some examples, but they're for InfluxDB v2 which I can't use.

Upvotes: 0

Views: 35

Answers (1)

Suyash
Suyash

Reputation: 335

You can try the following InfluxQL query for a Grafana panel:

SELECT DIFFERENCE(last("consumption")) AS "hourly_consumption" 
FROM "gas_meter" 
WHERE $timeFilter 
GROUP BY time(1h) 
FILL(0)

It calculate the difference using DIFFERENCE function between each time interval grouped hourly. FILL function ensures any data is reported as zero consumption.

Upvotes: 0

Related Questions