Hello ! I have this Flux script:
cpu_usage = from(bucket: "monitoring")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "cpu")
|> filter(fn: (r) => r["_field"] == "usage_idle")
|> filter(fn: (r) => r["cpu"] == "cpu-total")
|> group(columns: ["host"])
|> last()
|> map(fn:(r) => ({ _value: 100.0 - r._value,}))
|> filter(fn: (r) => r["_value"] > 0)
|> group()
|> count()
|> yield(name: "cpu_usage")
mem_usage = from(bucket: "monitoring")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "mem")
|> filter(fn: (r) => r["_field"] == "used_percent")
|> group(columns: ["host"])
|> last()
|> filter(fn: (r) => r["_value"] > 0)
|> group()
|> count()
|> yield(name: "mem_usage")
disk_usage = from(bucket: "monitoring")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "disk")
|> filter(fn: (r) => r["_field"] == "used_percent")
|> filter(fn: (r) => r["path"] == "/")
|> group(columns: ["host"])
|> last()
|> filter(fn: (r) => r["_value"] > 0)
|> group()
|> count()
|> yield(name: "disk_usage")
union(tables: [cpu_usage, mem_usage, disk_usage])
|> sum()
What I do is 3 different counts and the one with union() to add them.
What I want is that it only returns the sum of the union() function that has a value of 3. To show it in a Singlestat panel. And drop the other three tables from each count.
Thanks !