Hello,
Currently on Grafana v7.5.6 with InfluxDB v2.0.5
I have a graph visualization of sensor data with the following query:
from(bucket:"mybucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "TimeDomain")
|> filter(fn: (r) => r["Channel"] == "Ch0")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregatedWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: "last")
Typically this data is graphed in a panel set for the “last 5 min”. I would like to add another field that is the sum of the max() - min() of the last N number of data points. So each point of the added field would be the difference between the max() and min() of the previous N points.
Is something like this possible?
Thank you!
After some fumble farting around I think what I am looking for is a movingSpread() function, which doesnt seem to exist. Something like this:
from(bucket:"mybucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "TimeDomain")
|> filter(fn: (r) => r["Channel"] == "Ch0")
|> filter(fn: (r) => r["_field"] == "value")
|> movingSpread(n: # of points)
|> yield()
It looks like influx allows custom aggregate functions. Ima see if I can get something to work.
Turned out to be a one liner if the moving spread is based on time rather than number of points : )
from(bucket:"mybucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "TimeDomain")
|> filter(fn: (r) => r["Channel"] == "Ch0")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: Ns, fn: spread, createEmpty: false)
|> yield()