Hi,
I have these charts representing the values of a dozen different devices over time. These measures are stored in the same “Teleinformation” measurement :
For example, at 9:04:00, I have one value per device which is part of the group with code “myGroupCode” :
These charts are created with this Flux query (I have data every 10s, but it’s ok to downsample for visualization) :
from(bucket: "my-bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Teleinformation")
|> filter(fn: (r) => r["groupCode"] == "myGroupCode")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
And I want to create a continuous chart representing the sum of these charts, which I try doing this :
from(bucket: "my-bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Teleinformation")
|> filter(fn: (r) => r["groupCode"] == "myGroupCode")
|> group(columns: ["_time"], mode: "by")
|> sum(column: "_value")
|> aggregateWindow(every: 120s, fn: mean, createEmpty: false)
|> yield(name: "sum")
This ALMOST works, buy it gives a series of different vertical small charts every 2 minutes having each their own color (it’s like for each “_time”, I have a range of values instead of one value) :
Here, the same with a zoom around 9 a.m. :
For example, at 9:04:00, I can see many different values vertically, where I want only ONE value, from 641.4 to 956.9 (please ignore the negative sign, I’ve just applied this “map” for some purpose : |> map(fn: (r) => ({r with _value: - r._value}))
) :
If you watch it from a far distance, it’s KIND OF the sum of the other graphs, but it would be nicer to have one single chart as a result.
Can you please give me the secret Flux command to have one single continuous chart as a result ? (I’ve already read this, which is on a similar subject, but it didn’t help : Window and aggregate data in InfluxDB with Flux | InfluxDB Cloud (TSM) Documentation)
UPDATE :
Hey, after reading Group data in InfluxDB with Flux | InfluxDB Cloud (TSM) Documentation, I think I’ve got it :
from(bucket: "my-bucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Teleinformation")
|> filter(fn: (r) => r["groupCode"] == "myGroupCode")
|> group(columns: ["_time"], mode: "by")
|> aggregateWindow(every: 120s, fn: sum, createEmpty: false)
|> group(columns: ["_value", "_time"], mode: "except")
Which gives me :
This Flux syntax sounds extremely non intuitive, but well, at least it finally works and it’s pretty fast.
If anyone has some improvement to bring for readability or performance or anything, you are welcome
Now, for each existing “groupCode”, I’d like to calculate the “sum” chart just like this and store it into a new measurement/table. If this is achievable with Flux, it would be great.