'Grafana query to generate a cumulative sum from the same time every day
I need to present a Grafana time series graph starting at 05:00 every day. The time series graph needs to show a cumulative sum of 2 mass flow meters until 05:00 the next day, at which time it resets to zero, and then starts summing again.
What I have so far is the cumulative sum figured out, but have manually set the range to 05:00.
from(bucket: "ShortTerm")
|> range(start: 2021-09-17T05:05:00Z)
|> filter(fn: (r) => r["_measurement"] == "pulp_mflow1" or r["_measurement"] ==
"pulp_mflow2")
|> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
|> cumulativeSum()
|> yield(name: "mean")
Any suggestions?
Solution 1:[1]
At first hourSelection
came to mind, but it does not seem to handle midnight rollover. So for lack of better way, this may work:
import "date"
import "experimental"
hour = date.hour(t: now())
d0 = date.truncate(t: now(), unit: 1d)
t0 = if hour >= 5 then experimental.addDuration(d: 5h, to: d0) else experimental.subDuration(d: 19h, from: d0)
from(bucket: "ShortTerm")
|> range(start: t0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | alespour |