Influxdb2 downsampling

Hello Everyone.
i want to use Grafana on a icinga system. i installed influxdb2 for grafana. i used to have graphite on grafana but now i want to have influxdb2
i used to have retentions on grafana like this: retentions = 5m:10d,30m:90d,360m:2y
i read that to implement this i have to use downsampling. But the behavior of tasks in downsampling is very weird. please tell me what am i doing wrong.
i have a main bucket which name is icinga.
i creates another bucket forexample for 5 minute retention for all the data in icinga bucket from the first day that this bucket is creates and works which is 28.02.
i wrote this task: in a the file: “collect_downsample_5min”

option task = {name: “collect_downsample_5mintask”, every: 5m}

from(bucket: “icinga”)
|> range(start: 0)
|> filter(fn: (r) => r._field == “value”)
|> aggregateWindow(every: 5m, fn: mean)
|> to(org: “autostadt”, bucket: “collect_downsample_5min”)

it works very good and the data in it starts from 28.02

but as a test i created another bucket for 2day retention from icinga bucket. and the task is:

option task = {name: “test”, every: 2m}

from(bucket: “icinga”)
|> range(start: 0)
|> aggregateWindow(every: 2d, fn: mean)
|> to(org: “autostadt”, bucket: “icinga-2day-retention”)

but it shows the data only from 06.03 and not from 28.02
i tries the other inputs for start field like : 2024-02-28T13:35:00Z, stop: 2024-03-14T00:00:00Z
but the problem is still there.
can you please tell me why?

i am very thankful for your help.

Hello @peg,
Usually downsampling involves working with recent data or streaming or real time data which is why

|> range(start:  -task.every)

is used.

It looks like you’re performing historical downsampling of all of your data, which I wouldn’t suggest doing for your task. This task will probably fail as your data increases with time. In other words using start:0 is considered bad practice.

Are you able to query that data without a task?

from(bucket: “icinga”)
|> range(start:  2024-02-28T13:35:00Z,  stop: 2024-03-14T00:00:00Z)
|> aggregateWindow(every: 2d, fn: mean)

What does the above query return? First verify that you are getting query between those ranges. Then that the aggWindow function is operating as you expect.
The way that I usually debug tasks is to just try to run the query outside of task.

after you run that query once and have performed the historical downsampling I would change to start: -task.every so that your task can be more performant and not have to recalculate and rewrite a bunch of old data every time.

Thank you very much for your answer :slight_smile:

1 Like

@peg yay! I’m glad it helped thanks for your question