I am using influxdb 2.7.1 with Grafana 9.4.7.
Suppose I have the following in my influxdb:
In bucket “A” → “_measurement” = “meas_1” with “_field” = “a”, “b” and “c”
In bucket “A” → “_measurement” = “meas_2” with “_field” = “d”
In bucket “B” → “_measurement” = “meas_3” with “_field” = “e”, “f”
In bucket “B” → “_measurement” = “meas_4” with “_field” = “g”, “h”, “i” and “j”.
Within a “_measurement”, the timestamp of all “_field” are aligned. but the timestamp of the “_field” from “_measurement” to another “_measurement” is not.
Thus suppose I do a query like
from(bucket:“A”)
|> range(start: 0)
|> filter(fn:(r) => r._measurement == “meas_1” or r._measurement == “meas_2” )
|> filter(fn: (r) => r[“_field”] == “a” or r[“_field”] == “b” or r[“_field”] == “c” or r[“_field”] == “d” )
|> last()
Then I would get the value for “a”, “b” and “c” that all have the same timestamp, but “d” will have another timestamp.
What I would like is to do is to first query the last value of all fields of all measurements.
Then I would like to do a mixture of operations with these fields creating new fields that I would to visualized on grafana.
For example suppose I have retrieved the last values of all fields, then I want something like
“new_field_1” = “a” + “d”
“new_field_2” = “b” + 3*“g” + “e”
“new_field_3” = “c” - “f” + “j”
Here with “a” + “d” I mean the sum of the last values of fields “a” en “d”.
How can I achieve this using flux ? Can anyone supply me an example flux script on how to do this ? Note: I prefer not to use grafana transform
