Help with an influx query

Hello,

I’m a newbie and I would like some inputs for creating this query, I have this data:

Time ClientName
2024-04-05 14:11:41 VDI02
2024-04-05 13:53:41 VDI02
2024-04-05 14:34:10 VDI01
2024-04-05 14:11:40 VDI01
2024-04-05 13:53:41 VDI01
2024-04-05 14:11:40 PR-0145

And I would like to track given a timeframe how many Users are connected using this query:

from(bucket: “CITRIX”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “Citrix”)
|> filter(fn: (r) => r._field == “ClientName”)
|> distinct(column: “_value”)
|> count()
|> rename(columns: {_value: “Users”})
|> map(fn: (r) => ({hour: r._start, Users: r.Users}))

But that only gives me a result of all users connected on a given timeframe, instead of a series of count() for a given timeframe.

Results of the query:

hour Users
2024-04-04 09:18:19 3

Expected results:

hour Users
2024-04-04 13:00:00 2
2024-04-04 14:00:00 3

Any advice on how to map this result for every hour?

This did the trick so far, any other ideas are welcomed:

from(bucket: “CITRIX”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “Citrix”)
|> filter(fn: (r) => r._field == “ClientName”)
|> group()
|> aggregateWindow(every: 1h,fn: (column, tables=<-) => tables |> distinct() |> count())

1 Like

Hi @kuduka

Great solution! This dashboard calculates the sum for each hour of the day (so there are always 24 bars on the graph), and the time selector can span months or years. Therefore, even over long periods, one can see the sum (or average or count or whatever) by hour.