Grafana - adjust aggregatewindow to allow graphs over different timescales?

Grafana 9.4.7 self hosted under Docker on ubuntu server 22.04

I have a graph of light levels which are posted to influx every minute. I am querying this in influxql to plot on grafana and aggregating every 15 mins.

This works for short time spans eg xx but for 6 months it fails because there are too many data points.

I think the answer is in the value of aggregatewindow but I need to change that according to the time range to limit the number of datapoints.

Existing query -

from (bucket: “bucket1”)
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) => r._field == “A0”)
|> filter(fn: (r) => r[“host”] == “lt3”)
|> filter(fn: (r) => r[“topic”] == “TasmotaUp/SENSOR”)

How can I do this?

Thanks

Welcome @grimowl1 to the Grafana forum

You mentioned that you are aggregating every 15 minutes. I presume you are doing this before ingesting the data into InfluxDB, because there is nothing in your query that indicates the aggregation is being done.

If all of your data exists in Influx, I would think that an aggregateWindow statement like this placed after your last filter statement would work without any errors or crashes. Note that the fn: mean could be a different function (sum, last, custom function, etc.).

  |> aggregateWindow(every: 15m, fn: mean, createEmpty: false)

(PS: you said you are querying this in InfluxQL, but you are actually using Flux :smile:)

Hi Grant,

Thanks for replying. It was late when I posted that - I pasted the wrong query, it should look like this:

from (bucket: “bucket1”)
|> range(start: v.timeRangeStart, stop:v.timeRangeStop)
|> filter(fn: (r) => r._field == “Temperature”)
|> filter(fn: (r) => r[“host”] == “lt3”)
|> filter(fn: (r) => r[“topic”] == “TasmotaUp/SENSOR”)
|> aggregateWindow(every: 15m, fn: mean)

It doesn’t work for queries over eg 6 months due to the number of points. It would be better to aggregate over hours or even days as the time range increases. How can I do this?

Thanks

Hi @grimowl1

Thanks for explaining further. I think this thread should help you.

It does, but I can’t find any documentation on the units produced by something like ‘int(v: v.timeRangeStop) - int(v: v.timeRangeStart)’.

Specifically (for example), what number would result if we evaluate ‘int(v: v.timeRangeStop) - int(v: v.timeRangeStart)’ when there is 1 day between timeRangeStop and timeRangeStart?

Thanks

I think that question would be better for the InfluxDB forum. If you have not already posted there, I would suggest that.