Please correct flux query for grafa to calculate and display of a result for two columns AAA+BBB

280 views Asked by At

// I'm using sequences for insreting in FluxDB:

'sever1,submeas=XXX AAA=899265',
'sever1,submeas=XXX BBB=2281289',
'sever2,submeas=XXX BBB=2672',
'sever2,submeas=XXX AAA=0',
'sever3,submeas=XXX AAA=947439',
'sever3,submeas=XXX BBB=897226'
    

// Flux query

from(bucket: "llc")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "server1" or r["_measurement"] == "server2" or r["_measurement"] == "server3")
    |> filter(fn: (r) => r["_field"] == "AAA" or r["_field"] == "BBB")
    |> filter(fn: (r) => r["submeas"] == "XXX")
    |> aggregateWindow(every: v.windowPeriod, fn: mean,   createEmpty: false)
    |> yield(name: "mean")
    

// What should I do for AAA+BBB? I've tried just added this last condition, but It's not helped.

        |> map(fn: (r) => ({r with _value: r.AAA + r.BBB}))
1

There are 1 answers

0
Ferrum3000 On

I've found solution in docs for https://docs.influxdata.com/

from(bucket: "llc")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "server1" or r["_measurement"] == "server2" or r["_measurement"] == "server3")
  |> filter(fn: (r) => r["_field"] == "AAA" or r["_field"] == "BBB")
  |> filter(fn: (r) => r["submeas"] == "XXX")
  |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> map(fn: (r) => ({r with _value: (r.AAA + r.BBB)}))