[Solved] Aggregating data into a single field via Kapacitor

I am currently struggling to develop a tick script to aggregate multiple fields into a single field.I have something along the lines of the following, however it appears that my attempt to join the data is not working.

var kw1 = stream
                .where(lambda: "agent_host" == 'pdu1')

var kw2 = stream
                .where(lambda: "agent_host" == 'pdu2')

                .as('kw1', 'kw2')
        |eval(lambda: "kw1.Power" + "kw2.Power")

graph [throughput="0.00 points/s"];

stream0 [avg_exec_time_ns="0s" ];
stream0 -> from2 [processed="92000"];
stream0 -> from1 [processed="92000"];

from2 [avg_exec_time_ns="18.356µs" ];
from2 -> join4 [processed="46000"];

from1 [avg_exec_time_ns="7.515µs" ];
from1 -> join4 [processed="46000"];

join4 [avg_exec_time_ns="3.222µs" ];
join4 -> eval5 [processed="0"];

eval5 [avg_exec_time_ns="0s" eval_errors="0" ];
eval5 -> log6 [processed="0"];

log6 [avg_exec_time_ns="0s" ];
log6 -> influxdb_out7 [processed="0"];

I feel like there is something obvious I am missing here

The join node performs the join per group of incoming data. I think the simple fix in your case is to remove the .groupBy lines from the script. As its written now, the join node can’t join anything since the data is explicitly grouped by a tag that cannot match.


Unfortunately I’ve got some jitter in my timestamps and it seems that this script is only adding the two of them together when the timestamps match exactly. I thought that adding a window to each stream would group the two together such that the two values that came from the same pass of telegraf would get lumped together, but unfortunately that doesn’t seem to be the case.

And it looks like the last piece I was missing was specifying the tolerance on my join node.

Everything’s working as expected now.