using kapacitor with influxdb and collectd

I'm trying to integrate Kapacitor with our influxdb and collectd setup. However, It doesn't seem to work, and I don't understand why.

Collectd and Influxdb are running correctly, and I think Kapacitor is able to connect to influxdb. In the kapacitor log I see this:

[influxdb] 2016/04/22 09:46:42 I! started UDP listener for collectd_db default

This is the name of the influxdb database where collectd is recording metrics.

I created the following tick-file, and uploaded it to kapacitor and enabled it:

stream
    .from().measurement('cpu_value')
    .where(lambda: "type" == "percent")
    .where(lambda: "type_instance" == "idle")
    .alert()
        .crit(lambda: "value" <  100)
        // Whenever we get an alert write it to a file.
        .log('/tmp/alerts.log')

This was just a test script, which hopefully produces some output.

The script is enabled:

Name                          Type      Enabled   Executing Databases and Retention Policies
cpu_tick                      stream    true      true      ["collectd_db"."default"]

However, I don't see any recordings:

[centos@ip-xx-xx-xx-xx tmp]$ kapacitor list recordings
ID                                      Type    Size      Created      

"cpu_value" is a valid measurement in my database.

This is what I get in my error log:

[cpu_alert:stream1] 2016/04/28 13:00:51 E! error while evaluating WHERE expression: name "percent" is undefined. Names in scope: time,value,host,instance,type,type_instance

Author of Kapacitor here...

In Kapacitor lambda expressions single quotes vs double quotes have different meanings.

  • Single quotes indicate a string literal
  • Double quotes are a reference to a field or tag from the data.

This expression .where(lambda: "type" == "percent") is saying only keep data points who's type field or tag value is equal to the value of the percent field or tag. As per the err

[cpu_alert:stream1] 2016/04/28 13:00:51 E! error while evaluating WHERE expression: name "percent" is undefined. Names in scope: time,value,host,instance,type,type_instance

The percent field or tag does not exist.

You need to use single quotes if you want to filter points who's type value is equal to the percent literal.

.where(lambda: "type" == 'percent')

The same is probably true for your next expression as well.

.where(lambda: "type_instance" == 'idle')

Also you can AND expressions together if you wish

.where(lambda: "type" == 'percent' AND "type_instance" == 'idle')

When Kapacitor finds multiple where statements adjacent it converts them to an And'ed expression under the hood.

Here is relevant docs explaining the quotes differences https://docs.influxdata.com/kapacitor/v0.12/introduction/getting_started/#keep-the-quotes-in-mind

As for why there are no recordings I cannot answer without more context as to how you tried to create a recording.