Kapacitor stream processing multiple fields

after watching today’s webinar about advanced kapacitor the problem is solved the following way:

var period = 1s
var interval = 1s

var data = stream
|from()
    .database('db')
    .retentionPolicy('autogen')
    .measurement('ms1')
    .groupBy(*)
|window()
.period(period)
.every(interval)


var diff = data |eval(lambda: "latency1" - "latency2")
           .as('latency_diff')        
          |mean('latency_diff')
          .as('latency_diff')

var latency1 = data | mean('latency1')
                .as('value')

var latency2 = data|mean('latency2')
                .as('value')

diff 
| join(latency1,latency2)
        .as('lat1', 'lat2')
|influxDBOut()
    .database('db_cold')
    .retentionPolicy('autogen')
    .measurement('ms1')
    .precision('s')

thanks to Michael DeSa

1 Like