Is it possible, instead of having data streamed, to schedule kapacitor to do a check at 8:00am every day. Sort of like a cronjob?
I don't believe there's currently a way to schedule tasks to run at a specific time, however you can use a batch task to run queries on a specific schedule. For example, something like:
|query('''
SELECT mean("value")
FROM "telegraf"."default".cpu_usage_idle
WHERE "host" = 'serverA'
''')
.period(24h)
.every(24h)
...
Will execute a query similar to:
SELECT mean("value") FROM "telegraf"."default".cpu_usage_idle WHERE "host" = 'serverA' AND time > now() - 24h
Every 24 hours.
@evan-ty The batch query can also be scheduled via cron job syntax instead of flat periods.
https://docs.influxdata.com/kapacitor/v0.13/nodes/query_node/#cron
|query('''
SELECT mean("value")
FROM "telegraf"."default".cpu_usage_idle
WHERE "host" = 'serverA'
''')
.period(24h)
.cron('0 8 * * *')
@nathanielc
That is wonderful news. Thanks for your example, I really appreciate that!
Hello,
I haven't had much luck in getting this to work. I am using Kapacitor version 0.13 and it does not seem that batch commands have many examples on the internet.
In InfluxDB I have a database named "apple" and a measurement named 'reviewssubmitted'.
It has only time, and another column called 'submitted' which is just an integer.
I have a batch query like so:
https://paste.debian.net/794809/
To test, I adjusted the .cron fields every time as necessary to get an immediate run. However, nothing gets written to my emailsbounced.log. With my data, I know that the value will always be bigger than 10.
On InfluxDB when I run the exact same query I successfully get a result:
select stddev("submitted") FROM reviewssubmitted WHERE time > now() - 30d
name: reviewssubmittedtime stddev 1469888096242455145 2124.8363733004226I've tried wrapping the word time in quotations, and the now() - 30d in quotations to no luck.
Any help would be appreciated
@evan-ty For some examples on batch queries, I recommend reviewing the documentation here (though it doesn't include an example with cron).
From looking at the script, it's not immediately obvious what the issue might be. One thing you can do to help troubleshoot is by adding a log node to the script, which will log detailed information to the Kapacitor logs. For example, updating your script to:
var sd = batch
|query('''
SELECT STDDEV("submitted")
FROM "apple"."ninetydays".reviewssubmitted
WHERE "time" > now() - 30d
''')
.cron('18 16 * * *')
|log()
|alert()
.crit(lambda: "sd.stddev" > 10)
.log('/tmp/emailsbounced.log')
.email()
Also the output to a kapacitor show <task name> will help us greatly.
Most helpful comment
@evan-ty The batch query can also be scheduled via cron job syntax instead of flat periods.
https://docs.influxdata.com/kapacitor/v0.13/nodes/query_node/#cron