Hi all,
I would like to perform a math operation between 2 fields.
field 1 and field 2.
how would be the grafana query builder at the end for giving me some values.
Thanks in advance
Hi all,
I would like to perform a math operation between 2 fields.
field 1 and field 2.
how would be the grafana query builder at the end for giving me some values.
Thanks in advance
Hello,
Transformations, and especially Add field from calculation should help you solve your issue.
If you want more help on this, can you give a bit more detail on which datasource you’re using and which use case you want to solve?
The datasource in influxdb and info comes from telegraf.
Can you give me a screenshoot of how it would be in grafana?
Thanks
Sure, so you can have two different queries or one query returning 2 series. And then, you go to the Transform
tab, choose Add field from calculation
and you can do the following:
You can display only the Sum by enabling Replace all fields
.
Or you could use Flux for pulling the data from InfluxDB. It allows calculations between measurements:
Or very simply, if you have your two fields in a single measurement:
Note: this can probably work cross-measurements too, you just use an ‘or’ in the measurement filter and make sure you filter tight enough on other tags or field names.
from(bucket: “myBucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “myMeasurement”)
|> filter(fn: (r) => r[“_field”] == “myField1” or r[“_field”] == “myField2”)
|> map(fn: (r) => ({_time: r._time, _value: r._value, _field: r._field}))
|> pivot(rowKey:[“_time”], columnKey: [“_field”], valueColumn: “_value”)
|> map(fn: (r) => ({_time: r._time, myField1: r.myField1, myField2: r.myField2, myCalc: r.myField1 + r.myField2}))