I want to count the peak disc usage in a window of 5 mins. I am new to tick script and kapacitor. this is the sample code. The thing is I only want to count in the active window (not the emitted 2 min window, even if it had some data points).
var curr = stream
|from()
.measurement('disk_usage_root_used_percentage')
|window()
.period(5m)
.every(2m)
.align()
// here i want the count to happen
|alert()
.crit(lambda: "count" >5 )
.log('/tmp/alerts.log')
Q: How can I count the peak disc usage in a window of 5 minutes?
A: What is going to happen when you specify
period=5mandevery=2mis that, Kapacitor will buffer up 5 minutes worth of point data and try to write it to its pipeline every 2 minutes.So if the
streamtask were to go on for10m, you'll find that your TICK script will be executed5times in total.For each execution window, the dataset will consists of
3mof older data and2mof the newer ones. Essentially they are overlapped, this is bad because your use case here is to only analyse the latest5mpoint data and raise alarms if required, not looking back old data. In other words, you don't want to be spammed by false alarms.To correct it, you will need to specify
.period=5mand.every=5mfor thewindownode. Doing so you'll find that the TICK gets ran twice upon 10 minutes up time, with each run consisting of the latest 5 minutes worth of data.Let me know if this helps.