influxdata / influxdata/kapacitor
Error on defining new task in kapacitor
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
Hi @nathanielc,
Facing issue when defining new task in kapacitor.
**kapacitor define print_cpu3 -tick /tmp/kapacitor_udf/print_cpu.tick -type stream -dbrp "telegraf".'autogen'**
I have restarted my kapacitor and tried but no success.
Below are my code.
print_cpu.tick
var alpha = 0.001
var data = stream
|from()
.measurement('ping')
data
//Run our tTest UDF on the hotend temperature
@tTest()
|alert()
.id('url')
.crit(lambda: 0 > alpha)
.log('/tmp/kapacitor_udf/hotend_failure.log')**
````
Handler code
**Cpu_proc.py**
````
from kapacitor.udf.agent import Agent, Handler
from scipy import stats
import math
import udf_pb2
import sys
class CpuprocessHandler(Handler):
def __init__(self, agent):
self._agent = agent
self._hostname = ''
def info(self):
response = udf_pb2.Response()
response.info.wants = udf_pb2.STREAM
response.info.provides = udf_pb2.STREAM
response.info.options['url'].valueTypes.append(udf_pb2.STRING)
return response
def init(self, init_req):
success = True
msg = ''
for opt in init_req.options:
if opt.name == 'url':
self._hostname = opt.values[0].stringValue
if self._hostname is None:
success = False
msg += 'Hostname field must be supplied'
response = udf_pb2.Response()
response.init.success = success
response.init.error = msg[1:]
return response
def snapshot(self):
response = udf_pb2.Response()
response.snapshot.snapshot = ''
return response
def restore(self, restore_req):
response = udf_pb2.Response()
response.restore.success = False
response.restore.error = 'not implemented'
return response
def begin_batch(self, begin_req):
pass
#print >> sys.stderr, "Start receiving batch", begin_req
def point(self, point):
response = udf_pb2.Response()
response.point.CopyFrom(point)
host = response.point.tags[self._hostname]
#print >> sys.stderr, "Poinst Data: ", response.point
email = "bharavpatel"
response.point.email = email
self._agent.write_response(response, True)
def end_batch(self, batch_meta):
pass
#print >> sys.stderr, "End reciving batch", batch_meta
if __name__ == '__main__':
# Create an agent
agent = Agent()
h = CpuprocessHandler(agent)
agent.handler = h
print >> sys.stderr, "Starting agent for CpuprocessHandler"
agent.start()
agent.wait()
print >> sys.stderr, "Agent finished"
````
My kapacitor.conf file
````
[udf]
[udf.functions]
[udf.functions.tTest]
# Run python
prog = "/usr/bin/python2"
# Pass args to python
# -u for unbuffered STDIN and STDOUT
# and the path to the script
args = ["-u", "/tmp/kapacitor_udf/Cpu_proc.py"]
# If the python process is unresponsive for 10s kill it
timeout = "10s"
# Define env vars for the process, in this case the PYTHONPATH
[udf.functions.tTest.env]
PYTHONPATH = "/tmp/kapacitor_udf/kapacitor1/udf/agent/py"
````
Contributor guide
Research direction
Reproduce the `kapacitor define` command for `print_cpu.tick` and capture the missing error output first. Then inspect the referenced `Cpu_proc.py` handler and the `[udf.functions.tTest]` section in `kapacitor.conf`; done means the task defines successfully and the configured UDF can run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, python
- Domain
- backend, observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100