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}))
Hi,
I think I have an equal problem.
I would like to add to values. But the problem is, that they are not at the exact same time.
So the calculation ist zero + value, which is only one chart.
How cann I fix this problem.
Here are tow pictures:
Hi @ck76
If you are using Flux, you can use this function to normalize the timestamps:
Hi @grant2
could you explain every step I need. Iḿ not experienced in influxDB.
Which screenshots must I send?
thanks for your help, I found the solution in Grafana.
For the benefit of future readers in this forum, can you share your solution?