Influx 2.0 (flux) queries in grafana are a little on the messy side. Here are a comple of examples that might be useful.
Here is an example of summing up a number of fields for display on a "single stat" panel widget
from(bucket: "powermon")|> range(start: -1h)|> filter(fn: (r) => r._measurement == "modbus")|> filter(fn: (r) => r._field == "pv1" or r._field == "pv2" or r._field == "pv3" or r._field == "pv4" or r._field == "pv5" or r._field == "pv6" or r._field == "pv7")|> last()|>keep(columns:["_value"])|> sum()
When playing with graphs, things are more or less as you'd expect:
from(bucket: "powermon")|> range(${range})|> filter(fn: (r) => r._measurement == "modbus")|> filter(fn: (r) => r._field == "pv1" or r._field == "pv2" or r._field == "pv3" or r._field == "pv4" or r._field == "pv5" or r._field == "pv6" or r._field == "pv7")|> aggregateWindow(every: 1m, fn: (tables=<-, column) => {return tables |> mean(column: column) |> map(fn: (r) => ({r with _value: r._value*1000.0}))})|> yield(name: "mean")
No comments:
Post a Comment