I am trying to get kapacitor to trigger an alert based on collectd data in influxdb. Am basing my tick file on the answer in using kapacitor with influxdb and collectd.
stream
// Select just the cpu measurement from our example database.
|from()
.measurement('cpu_value')
.where(lambda: "type" == 'percent' AND "type_instance" == 'idle')
|alert()
.crit(lambda: "value" < 98)
// Whenever we get an alert write it to a file.
.log('/tmp/alerts.log')
I have defined the alert as per kapacitor docs:
kapacitor define cpu_alert -type stream -tick cpu_alert.tick -dbrp collectd.default
Appropriate data is being sent to influxdb from collectd and available via query:
select value from /cpu_value/ where type='percent' and type_instance = 'idle' order by time desc limit 10;
However running :
kapacitor record stream -task cpu_alert -duration 20s &
does not record any data:
$ kapacitor list recordings
ID Type Status Size Date
48e5c04a-68c2-44a3-ba80-f2c12d952994 stream running 0 B 19 Jul 16 11:57 IST
I suspect that I may not be correctly referencing the database when I register the task, but cannot see where I have an error.
The root cause was incorrect configuration. Pay attention to the "influxdb.subscriptions" and "influxdb.excluded-subscriptions" sections of the kapacitor.conf file.
By default kapacitor subscribes to all Influx DBs. I wanted it only to subscribe to one DB, but erroneously included this in the "influxdb.excluded-subscriptions" section rather than the "influxdb.subscriptions".
You can see what subscriptions are active by issuing a "SHOW SUBSCRIPTIONS" query to influxdb.