Kapacitor: HoltWinters with streaming data

Hi,
can someone give me an example of how to use the Holt-Winters function in Kapacitor with a stream instead of a batch? Is it even possible?

Best regards,
Simon

@sj14 With data points like packets,host=serverA value=1000 0000000001

The following should work.

stream
	|from()
		.measurement('packets')
		.groupBy('host')
	|window()
		.period(10s)
		.every(10s)
	|holtWinters('value', 3, 0, 1s)
	|where(lambda: "host" == 'serverA')
	|httpOut('TestStream_HoltWinters')

@jackzampolin Thanks you very much, it works.
My stream replay file has data like (giving more data would indicate kind of a sinus wave/cycling pattern):

mydb
autogen
table_test key="1",value=-0.021337869145268 0
mydb
autogen
table_test key="2",value=0.00881807571161336 10000000000
mydb
autogen
table_test key="3",value=0.0758696736565443 20000000000
mydb
autogen
table_test key="4",value=0.102036289877147 30000000000

and the script looks like:

var data = stream
|from()
    .measurement('table_test')
|window()
    .period(1d)
    .every(10m)

var hw = data
|holtWinters('value', 1, 0, 10m)
    .as('pred')
|alert()
    .crit(lambda: "pred" > TODO)

So far so good. Know I want to compare the predicted value with the incoming value and use it for anomaly detection. If the incoming value is too far away from the predicted value (maybe by using 3-sigma), the alarm should be triggered.
Is it possible to compare both values. Probably I have to store the predicted value in the database first, or is it possible to do “on the fly”?

Best regards,
Simon

@sj14 You will need to store the value in the database first. Might want to think about storing them as separate fields in the same measurement.

Hi Simon,

Were you able to figure out how to compare predicted value with incoming value. In the above script, current value is also used by holtwinters for forecasting. so by not using current value for holt winters and comparing current value with predict value should be good anomaly detection. Please let me know if you have any update on that…

Best Regards,
Kranthi