# Kapacitor question

**URL:** <https://community.influxdata.com/t/kapacitor-question/7500>\
**Category:** Telegraf\
**Created:** [November 20, 2018, 4:07am UTC](https://community.influxdata.com/t/kapacitor-question/7500 "2018-11-20T04:07:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiagocorredor](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/thiagocorredor/32/2312_2.png) [@thiagocorredor](https://community.influxdata.com/u/thiagocorredor)\
**Post date:** [November 20, 2018, 4:07am UTC](https://community.influxdata.com/t/kapacitor-question/7500/1 "2018-11-20T04:07:38Z")

</div>

Good evening all !

I have a tick script, used as stream Node.

The script keep looking new data for a specific table, and insert some sum of data in other table. So I am able to perform faster queries.

My issue is that the values of these tables are not the same at the end of the day (and I believe should be).

This is the comparative (example of one week):

> SELECT count(“time\_taken”) FROM “web\_logs\_iis” WHERE (“hostname” =~ /^hostname$/) and time \>= ‘2018-11-11 00:00:00’ and time \<= ‘2018-11-17 23:59:59’  
> name: web\_logs\_iis  
> time count

* * *

2018-11-11T00:00:00Z **3.157.175**

> SELECT sum(“total”) FROM “apm\_apex” WHERE (“hostname” =~ /^hostname$/) and time \>= ‘2018-11-11 00:00:00’ and time \<= ‘2018-11-17 23:59:59’  
> name: apm\_apex  
> time sum

* * *

2018-11-11T00:00:00Z **21.010.226**

And this is the tick script.

Am I using some incorrect variable? Any help will be appreciated.

var t\_satisfied = 20000

var t\_tolerating = 60000

var fromMeasurement = ‘web\_logs\_iis’

var toMeasurement = ‘apm\_apex’

var database = ‘80’

var retention = ‘quarterly’

var period = 1m

var every = 1m

var requests = stream  
|from()  
.measurement(fromMeasurement)  
.groupBy(‘hostname’)  
|window()  
.fillPeriod()  
.period(period)  
.every(every)

var total = requests  
|count(‘time\_taken’)  
.as(‘total’)  
|groupBy(‘hostname’)  
|httpOut(‘total’)

var failed = requests  
|where(lambda: int(“protocol\_status”) \>= 400)  
|count(‘time\_taken’)  
.as(‘failed’)  
|groupBy(‘hostname’)  
|httpOut(‘failed’)

var satisfied = requests  
|where(lambda: int(“time\_taken”) \<= t\_satisfied AND int(“protocol\_status”) \< 400)  
|count(‘time\_taken’)  
.as(‘satisfied’)  
|groupBy(‘hostname’)  
|httpOut(‘satisfied’)

var tolerating = requests  
|where(lambda: int(“time\_taken”) \> t\_satisfied AND int(“time\_taken”) \<= t\_tolerating AND int(“protocol\_status”) \< 400)  
|count(‘time\_taken’)  
.as(‘tolerating’)  
|groupBy(‘hostname’)  
|httpOut(‘tolerating’)

var frustrated = requests  
|where(lambda: int(“time\_taken”) \> t\_tolerating AND int(“protocol\_status”) \< 400)  
|count(‘time\_taken’)  
.as(‘frustrated’)  
|groupBy(‘hostname’)  
|httpOut(‘frustrated’)

var good\_rate = satisfied  
// |log()  
// .level(‘DEBUG’)  
|join(tolerating)  
.as(‘satisfied’, ‘tolerating’)  
// .fill(‘none’)  
|eval(lambda: float(“satisfied.satisfied”) + (float(“tolerating.tolerating”) / 2.0))  
.as(‘good\_rate’)  
|httpOut(‘good\_rate’)

var apex = total  
|join(good\_rate)  
.as(‘total’, ‘good\_rate’)  
|eval(lambda: float(“good\_rate.good\_rate”) / float(“total.total”))  
.as(‘apex’)  
|httpOut(‘apex’)

total  
|influxDBOut()  
.create()  
.database(database)  
.retentionPolicy(retention)  
.measurement(toMeasurement)  
.tag(‘kapacitor’, toMeasurement)  
.flushInterval(1s)

failed  
|influxDBOut()  
.create()  
.database(database)  
.retentionPolicy(retention)  
.measurement(toMeasurement)  
.tag(‘kapacitor’, toMeasurement)

satisfied  
|influxDBOut()  
.create()  
.database(database)  
.retentionPolicy(retention)  
.measurement(toMeasurement)  
.tag(‘kapacitor’, toMeasurement)

tolerating  
|influxDBOut()  
.create()  
.database(database)  
.retentionPolicy(retention)  
.measurement(toMeasurement)  
.tag(‘kapacitor’, toMeasurement)

frustrated  
|influxDBOut()  
.create()  
.database(database)  
.retentionPolicy(retention)  
.measurement(toMeasurement)  
.tag(‘kapacitor’, toMeasurement)

apex  
|influxDBOut()  
.create()  
.database(database)  
.retentionPolicy(retention)  
.measurement(toMeasurement)  
.tag(‘kapacitor’, toMeasurement)
