Can't get to work the outliers detection example

Hi All, :blush:

I am just a novice learning to use TICK stack, and I have been trying to use the “outliers.py” example from kapacitor/outliers.py at master · influxdata/kapacitor · GitHub with my influxDB.

I have the kapacitor repository cloned into ~/Documents/anomalies/
I don’t know what I’m doing wrong but I can’t get it to work. :disappointed:

My [udf] section in kapacitor.conf:

[udf]
# Configuration for UDFs (User Defined Functions)
[udf.functions]

[udf.functions.outliers]
    # Run python
    prog = "/usr/bin/python2"
    # Pass args to python
    # -u for unbuffered STDIN and STDOUT
    # and the path to the script
    args = ["-u", "~/Documents/anomalies/kapacitor/udf/agent/examples/outliers/outliers.py"]
    # If the python process is unresponsive for 10s kill it
    timeout = "5m"
    # Define env vars for the process, in this case the PYTHONPATH
    [udf.functions.outliers.env]
        PYTHONPATH = "~/Documents/anomalies/kapacitor/udf/agent/py"

My tickscript:

var data = batch
    |query('SELECT * FROM "grafana_db".."CPU temperature" WHERE time > now() - 5m')
        .period(5m)
        .every(5m)

data
    @outliers()
        // specify the value field
        .field('value')
    |alert()
        .message('Levedata: {{ index .Fields "lvl" }}; Prefix data {{ index .Fields "value" }}')
        .crit(lambda: "value" >0.0)
        .StateChangesOnly()
        .log('~/Documents/anomalies/outliers.log')

If I check for logs, this is my output:

sudo tail -n 150 /var/log/kapacitor/kapacitor.log | grep "UDF log"
ts=2018-11-21T18:39:23.473+01:00 lvl=info msg="UDF log" service=udf text="2018-11-21 18:39:23,473 INFO:root: Starting Agent"
ts=2018-11-21T18:39:23.473+01:00 lvl=info msg="UDF log" service=udf text="2018-11-21 18:39:23,473 INFO:root: info"
ts=2018-11-21T18:39:23.474+01:00 lvl=info msg="UDF log" service=udf text="2018-11-21 18:39:23,474 INFO:root: Agent finished"

It just starts, goes into “info” method into outliers.py and finishes. :disappointed_relieved:

Some examples of the data that I retrieve with the outliers.tick query:

SELECT * FROM "grafana_db".."CPU temperature" WHERE time > now() - 5m
name: CPU temperature                                                                                                                                                                                                                        
time                 applications group_name      host_name      value value_avg value_max value_min                                                                                                                                         
----                 ------------ ----------      ---------      ----- --------- --------- ---------                                                                                                                                         
2018-11-21T17:49:03Z CPU          Grupo de prueba Host de prueba 40.6                                                                                                                                                                        
2018-11-21T17:49:04Z CPU          Grupo de prueba Host de prueba 40.6                                                                                                                                                                        
2018-11-21T17:49:05Z CPU          Grupo de prueba Host de prueba 40.4                                                                                                                                                                        
2018-11-21T17:49:06Z CPU          Grupo de prueba Host de prueba 39.8                                                                                                                                                                        
2018-11-21T17:49:07Z CPU          Grupo de prueba Host de prueba 39.8                                                                                                                                                                        
2018-11-21T17:49:08Z CPU          Grupo de prueba Host de prueba 40.4                                                                                                                                                                        
2018-11-21T17:49:09Z CPU          Grupo de prueba Host de prueba 40.4                                                                                                                                                                        
2018-11-21T17:49:10Z CPU          Grupo de prueba Host de prueba 40.4                                                                                                                                                                        
2018-11-21T17:49:11Z CPU          Grupo de prueba Host de prueba 40.4

Can someone help me? :sob:

Hi , have you seen this document ?
Best regards

https://docs.influxdata.com/kapacitor/v1.5/guides/anomaly_detection/

Hi MarcV, thank you for your reply. :smiley:

Yes, I followed all the instructions in that document, but the outliers example is not working for me… :sob:

For anyone with the same problem:

I forgot to set the retention policy in the TICK script.

With this change on the TICKscript query, it was solved:

"grafana_db".."CPU temperature"

to

"grafana_db"."autogen"."CPU temperature"

:slight_smile: