Sum() with mutiple tables more than 2 tables

Hi,
I have the following problem and am in despair.
I have a bucket with several servers.
Now I want to find out how many users mometan
are online on all servers. I can monitor single servers (Windows) but I can’t get a sum of all servers (host).
I have tried with join or with union.
sum() does not work somehow.
Can someone give me a tip?
I use Grafana and Data Explorer from Inluxdb 2.0
Thanks :slight_smile:

I made it work. Here is the solution I took. Am of course open to anything else :slight_smile:

 HostA = from(bucket: "webApp")
  |> range(start: -1m)
  |> filter(fn: (r) => r["_measurement"] == "app_total")
  |> filter(fn: (r) => r["host"] == "HostA ")
  |> drop(columns:["instance","object","objectname","_field"])
  |> last()
  |> rename(columns: {_value: "total_HostA"})

HostB = from(bucket: "webApp")
  |> range(start: -1m)
  |> filter(fn: (r) => r["_measurement"] == "app_total")
  |> filter(fn: (r) => r["host"] == "HostB")
  |> drop(columns:["instance","object","objectname","_field"])
  |> last()
  |> rename(columns: {_value: "total_HostB"})


HostC = from(bucket: "webApp")
  |> range(start: -1m)
  |> filter(fn: (r) => r["_measurement"] == "app_total")
  |> filter(fn: (r) => r["host"] == "HostC")
  |> drop(columns:["instance","object","objectname","_field"])
  |> last()
  |> rename(columns: {_value: "total_HostC"})


HostJoin = join(tables: {total_HostA:HostA, total_HostB:HostB}, on: ["_time"], method: "inner" )
HostJoinA = join(tables: {total_HostA:HostJoin, total_HostC:HostC}, on: ["_time"], method: "inner" )

  |> keyValues(keyColumns: ["total_HostA", "total_HostB","total_HostC"])
  |> sum()
  |> yield(name: "mean")

Hello @OptimusOS,
Can you share some input and expected output?
Looking at your query I’m thinking:

HostC = from(bucket: "webApp")
 |> range(start: -1m)
 |> filter(fn: (r) => r["_measurement"] == "app_total")
 |> filter(fn: (r) => r["host"] == "HostA" or r["host"] == "HostB"  or r["host"] == "HostC")
 |> group()
 |> sum()

…that that might work?

Hi @Anaisdg,
thx for reply
I have already tried but the problem is the following:
I get every 5 seconds a record from all servers.
If I sum up this value I get a very high number that can not be correct in the snapshot,
because it adds as in your case 12 values per host and makes me a result out of it.
Example: HostA = 12 User; HostB = 18 User; HostC = 10 User >
If the result would be 40 users but in your case, I would get 480 users out (1m(<=range(start: -1m) \ 5s (dataset delay ) = 12 datasets per minute).

:slight_smile: