Search code examples
influxdbflux-influxdb

Finding the Count per field for a Window using Flux Query - InfluxDB


I am trying to display data where it aggregates by a field and displays count per a window. I'm struggling coming up with the syntax. Let's assume this is my data in InfluxDb:

import "array"

data = array.from(rows: [
  {application: "ap1", time: "2022-10-01T10:10:06.757Z", message: "error..."},
  {application: "ap2", time: "2022-10-03T15:11:05.757Z", message: "error..."},
  {application: "ap1", time: "2022-10-02T12:11:08.757Z", message: "error..."},
  {application: "ap1", time: "2022-10-04T13:13:05.757Z", message: "error..."},
  {application: "ap3", time: "2022-10-05T10:11:16.757Z", message: "error..."},
  {application: "ap3", time: "2022-10-06T15:22:05.757Z", message: "error..."},
])

data
 |> group(columns: ["application", "time"])

I'd like to group by results like this:

enter image description here

The window could be...show count per application type...per hour, per day, or per week.


Solution

  • You could try with the count function.