Using values from one Kapacitor batch in another

Hey there!

I’m currently trying to implement a flow in Kapacitor to post-process our data, with no luck at the moment. And I was hoping if someone can help us to get a bit of light with the problem we are facing right now.

We need to:

  1. Count elements in a timespan from a measurement: done with a batch
  2. Count elements from another measurement that have a integer field (unix timestamp) between max and minimum values of the elements of the first set of elements.

And that’s the issue we are facing. We are getting minimum and maximum values of the timestamps with something like (fake names because of NDA :joy:) :

var firstCount = batch
    |query('SELECT count("someField") as countItems, min("myTimestamp") as minTimestamp, max("myTimestamp") as maxTimestamp FROM "DatabaseName"."autogen"."MeasurementName"')
        .period(1h)
        .every(15s)
        .fill(0)
        .align()

But we get stocked when querying second measurement, as we cannot assign those field values to variables to use them later on the second query.

We also tried to join both queries, but as the first one only returns one element, we cannot filter with a where node to then count items…

Also, getting all points of that first query instead of a reduced one doesn’t seem like a good idea since that measurement can potentially have 100k’s of series per hour :confused:

Any idea?

Thank to you all for such an amazing community!

As I was filtering y a different timestamp, I end up just applying the timestamp to the point itself and that worked as a work around!