5

Given a bucket how do I get the number of points in this bucket with the timestamp in the given time interval using a Flux query?

I'm trying to estimate how much data is added to an influxdb2 bucket per unit of time.

axk
  • 5,316
  • 12
  • 58
  • 96

2 Answers2

6

This is what I ended up doing:

from(bucket: "mybucket")
  |> range(start: -1m)
  |> group()  
  |> count()

In my case there's a very big number of series (table streams returned by from) in the bucket so I had to add group() with no arguments to combine it into a single table before count(). It would return the count for each table separately otherwise.

From the flux manual:

An empty group key groups all data in a stream of tables into a single table

axk
  • 5,316
  • 12
  • 58
  • 96
3

I think it should look something like this:

from(bucket: "my_bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "my_measurement")
  |> window(period: 30s)
  |> group(columns: ["_start"])
  |> count()

At the first we separete out data by time window |> window(period: 30s) Then we group by new _start time and get count of records.

Amerousful
  • 2,292
  • 1
  • 12
  • 26
  • thanks! in my case there's a very big number of series (table streams returned by `from`) in the bucket so I had to add group() with no arguments to combine it into a single table before count() – axk Jan 18 '22 at 16:37
  • @axk Yes, my initial answer/query was the same as yours, but then I saw in your question a clarification about `per unit of time` and added `window` for that. Anyway I was glad to help :) – Amerousful Jan 18 '22 at 17:15