influxdb-2

aggregate the count if fields in a measurement in Influxdb2


I have a measurement "m1" in influxdb2 where data is labeled with 4 different labels, lets call the l1 - l5. All have a float variable (seconds).

I can count per field with the following query:

from(bucket: "my bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "m1")
  |> count()
  |> yield(name: "count")

i will get raw data with 5 rows, 1 row for each field with the count of the values per field.

How can I sum the 5 values to a single count over all fields?


Solution

  • You can ungroup the data and sum the values then.

    from(bucket: "my bucket")
      |> ...
      |> count()
      |> group()
      |> sum()