I write the data from my powermeter in the influxDB and display with Grafana.
But the function “aggregateWindow(every: 1mo, fn: last, createEmpty: true)” takes a loooong time. Because there are many data.
Is it possible that InfluxDB create automatic from a query a new measurement with the already aggregated datas?
Then I just need to read 12 values (Jan - Dec) and must not calculate at any query.
@hanhoe You should create an InfluxDB task that runs monthly and aggregates the data from the last month. The task can then store the data in a aggregated bucket that you can query from. Something like this:
So this task would run every month, query and aggregate data from the previous month, and then store it in the other aggregate bucket. Then, to query a year’s worth of just the monthly aggregates, you’d just do:
Doing that will likely take just as long as your first attempt. It still has to query all the data from the last year to generate the aggregate values for each month.
When I use:
|> aggregateWindow(every: 1d, fn: mean, createEmpty: false)
he need around 1s
When I use:
|> aggregateWindow(every: 1d, fn: last, createEmpty: false)
he need around 10s
Did you know why last has this delay?
With mean he need to read all values and calc the average
With last or first he “just” need read the last/first value
I don’t know the exact implementation details of these two functions, but they are inherently different. mean() is an aggregate function that returns the average of all values in a specific column in each input table. last() is a selector function function that returns the last row in each input table. If I had to guess, I would say that last() may take a little longer is it has to ensure sort order in its logic, but that’s only a guess.