Rajesh Rajendran
Rajesh Rajendran

Reputation: 607

count peak values in a data window, kapacitor

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')

Upvotes: 1

Views: 828

Answers (1)

Samuel Toh
Samuel Toh

Reputation: 19298

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=5m and every=2m is 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 stream task were to go on for 10m, you'll find that your TICK script will be executed 5 times in total.

For each execution window, the dataset will consists of 3m of older data and 2m of the newer ones. Essentially they are overlapped, this is bad because your use case here is to only analyse the latest 5m point 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=5m and .every=5m for the window node. 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.

Upvotes: 2

Related Questions