@@ -407,15 +407,15 @@ if __name__ == '__main__':
407
407
agent.handler = h
408
408
409
409
# Anything printed to STDERR from a UDF process gets captured into the Kapacitor logs.
410
- print >> sys.stderr, " Starting agent for TTestHandler"
410
+ print ( " Starting agent for TTestHandler" , file = sys.stderr)
411
411
agent.start()
412
412
agent.wait()
413
- print >> sys.stderr, " Agent finished"
413
+ print ( " Agent finished" , file = sys.stderr)
414
414
415
415
```
416
416
417
417
That was a lot, but now we are ready to configure Kapacitor to run our
418
- code. Create a scratch dir for working through the rest of this
418
+ code. Make sure that ` scipy ` is installed ( ` $ pip3 install scipy ` ). Create a scratch dir for working through the rest of this
419
419
guide:
420
420
421
421
``` bash
@@ -434,7 +434,7 @@ Add this snippet to your Kapacitor configuration file (typically located at `/et
434
434
[udf.functions]
435
435
[udf.functions.tTest]
436
436
# Run python
437
- prog = "/usr/bin/python2 "
437
+ prog = "/usr/bin/python3 "
438
438
# Pass args to python
439
439
# -u for unbuffered STDIN and STDOUT
440
440
# and the path to the script
@@ -468,8 +468,8 @@ correctly:
468
468
service kapacitor restart
469
469
```
470
470
471
- Check the logs (` /var/log/kapacitor/ ` ) to make sure you see a
472
- * Listening for signals * line and that no errors occurred. If you
471
+ Check the logs (` /var/log/kapacitor/ ` or ` journalctl -f -n 256 -u kapacitor.service ` ) to make sure you see a
472
+ _ Listening for signals _ line and that no errors occurred. If you
473
473
don't see the line, it's because the UDF process is hung and not
474
474
responding. It should be killed after a timeout, so give it a moment
475
475
to stop properly. Once stopped, you can fix any errors and try again.
@@ -544,6 +544,20 @@ the Kapacitor task:
544
544
kapacitor define print_temps -tick print_temps.tick
545
545
```
546
546
547
+ Ensure that the task is enabled:
548
+
549
+ ``` bash
550
+ kapacitor enable print_temps
551
+ ```
552
+
553
+ And then list the tasks:
554
+
555
+ ``` bash
556
+ kapacitor list tasks
557
+ ID Type Status Executing Databases and Retention Policies
558
+ print_temps stream enabled true [" printer" ." autogen" ]
559
+ ```
560
+
547
561
### Generating test data
548
562
549
563
To simulate our printer for testing, we will write a simple Python
@@ -557,7 +571,7 @@ to use real data for testing our TICKscript and UDF, but this is
557
571
faster (and much cheaper than a 3D printer).
558
572
559
573
``` python
560
- # !/usr/bin/python2
574
+ # !/usr/bin/env python
561
575
562
576
from numpy import random
563
577
from datetime import timedelta, datetime
@@ -672,7 +686,11 @@ fake data so that we can easily iterate on the task:
672
686
``` sh
673
687
# Start the recording in the background
674
688
kapacitor record stream -task print_temps -duration 24h -no-wait
675
- # Grab the ID from the output and store it in a var
689
+ # List recordings to find the ID
690
+ kapacitor list recordings
691
+ ID Type Status Size Date
692
+ 7bd3ced5-5e95-4a67-a0e1-f00860b1af47 stream running 0 B 04 May 16 11:34 MDT
693
+ # Copy the ID and store it in a variable
676
694
rid=7bd3ced5-5e95-4a67-a0e1-f00860b1af47
677
695
# Run our python script to generate data
678
696
chmod +x ./printer_data.py
0 commit comments