Hi,
I am new to kapacitor and using it to calculate percentages and totals using a batch function. This is being run side by side with the previous reporting solution.
I have run into a strange issue though where the values that kapacitor collects from InfluxDB and the values that return from the InfluxDB CLI. The values in kapacitor are one out (+1 on one field and -1 on the another).
I have checked the source data and the values stored in InfluxDB are correct, which leaves kapacitor.
Tick script (some data sensitive data removed):
var clearbags = batch
|query('''
SELECT last(bag_counts)
FROM "somedb"."autogen".conveyor
WHERE "conveyor" = 'name'
''')
.period(24h)
.every(24h)
.groupBy(time(1m))
.fill('previous')
// Get reject route counts
var rejectbags = batch
|query('''
SELECT last(bag_counts)
FROM "somedb"."autogen".conveyor
WHERE "conveyor" = 'name'
''')
.period(24h)
.every(24h)
.groupBy(time(1m))
.fill('previous')
// Join to get a total number of bags
clearbags
|join(rejectbags)
.as('clearbags', 'rejectbags')
|where(lambda: "clearbags.last" > 0 OR "rejectbags.last" > 0)
|log()
|eval(lambda: "rejectbags.last" / ("clearbags.last" + "rejectbags.last"))
.as('pct_to_level3')
|log()
|influxDBOut()
.database('somedb')
.retentionPolicy('autogen')
.measurement('line')
.tag('plc','none')
.tag('area','sss')
.tag('terminal','1')
.tag('conveyor','some')