Get the number of points in a bucket for a time interval with Flux query

Viewed 1565

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.

2 Answers

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.

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

Related