Influxdb window question

Want:
I want retrive the mean value between 2022-05-30T02:21:46.000000000Z and 2022-05-30T02:22:46.000000000Z, below is my dsl:

from(bucket:“telegraf”)
|> range(start:2022-05-30T02:21:46.000000000Z, stop:2022-05-30T02:22:46.000000000Z)
|> filter(fn: (r) => r["_measurement"] == “mem”)
|> filter(fn: (r) => r["_field"] == “used_percent”)
|> aggregateWindow(every:1m, fn:mean, createEmpty:false)
|> group(columns:[“host”])
|> yield(name:“mean”)

Expected:
one table per host

Actual:
two table per host,

Question:

  1. how to the window function work?
  2. how can i get the expected result?

Your screenshot shows one table per host (you have 3 hosts, and 3 tables).

It shows two values for each host though. I suspect what’s happening is that the start and stop in range is inclusive, so you’re actually asking for 61 seconds worth of data, not 60 seconds exactly. This means your aggregateWindow function has slightly more than one minute’s worth of data, and so it will produce two sets of outputs.

If you are always going to limit your range call to the period of time you want an average for, you don’t need to use aggregateWindow() you can instead just you mean() on the entire set or results. That will guarantee that you get only one value per table.

You should also run group(columns:["host"]) before your aggregate, so that it’s grouped according to what you want the aggregate for.

So, to summarize, try this:

from(bucket:"telegraf")
|> range(start:2022-05-30T02:21:46.000000000Z, stop:2022-05-30T02:22:46.000000000Z)
|> filter(fn: (r) => r["_measurement"] == "mem")
|> filter(fn: (r) => r["_field"] == "used_percent")
|> group(columns:["host"])
|> mean()
|> yield(name:"mean")