"Post http://localhost:9092/kapacitor/v1/tasks: dial tcp 127.0.0.1:9092: connect: connection refused" error with UDF Kapacitor


#1

Issues with UDF function in kapacitor.conf file.

I am trying to run a basic python script using UDF function through Kapacitor.
Here are the steps followed:

  1. Created a simple Python script that queries the Influxdb measurement ‘disk’.

tTest.py script:

def main():
import os
os.system('curl -G ‘http://172.19.99.31:8086/query?db=test’ --data-urlencode ‘q=select * from disk where used_percent=31’ > /home/kapacitor/result.txt ')

if name==“main”:
main()

  1. Configures the UDF function in kapacitor.conf file as:

Kapacitor.conf

[[influxdb]]
enabled = true
default = true
name = “test”
urls = [“http://172.19.99.31:8086”]

[udf]

Configuration for UDFs (User Defined Functions)

[udf.functions]
[udf.functions.tTest]
# Run python
prog = “/usr/bin/python2”
args = ["-u", “/tmp/kapacitor_udf/tTest.py”]
timeout = “10s”

  1. TICK file:

dbrp “test”.“autogen”

var data = stream
|from()
.measurement(‘disk’)
|window()
.period(5m)
.every(5m)

On defining the TICK script, below error pops up:

root@kapacitor:/etc/kapacitor# kapacitor define cpu_alert -tick cpu_alert.tick
Post http://localhost:9092/kapacitor/v1/tasks: dial tcp 127.0.0.1:9092: connect: connection refused

However, if i disable the UDF function configuration in kapacitor.conf file and update the tick script to execute the Python program as below, the python script runs fine.

TICK script with exec() function:

dbrp “test”.“autogen”

stream
|from()
.measurement(‘disk’)
|alert()
.crit(lambda: int(“used_percent”) = 31)
// Whenever we get an alert write it to a file.
.exec(’/usr/bin/python’,’/tmp/kapacitor_udf/tTest.py’)
.log(’/tmp/alerts.log’)

Please note that the Influx db and Kapacitor are on different machines as below:

kapacitor: 172.19.99.38
influxdb: 172.19.99.31