Exec event handler
exec 事件处理程序执行一个外部程序。事件数据通过 STDIN 传递到进程。
Options
以下 exec 事件处理程序选项可以在 handler 文件中设置,或者在使用 TICKscript 中的 .exec()
时设置。
Name | Type | Description |
---|---|---|
prog | string | 要执行的程序的路径。 |
args | list of string | 程序的参数列表。 |
Example: handler file
id: handler-id
topic: topic-name
kind: exec
options:
prog: /path/to/executable
args:
- 'executable arguments'
Example: TICKscript
|alert()
// ...
.exec('/path/to/executable', 'executable arguments')
Using the exec event handler
exec 事件处理程序可以在 TICKscript 和 handler 文件中使用,以根据警报逻辑执行外部程序。
Note: Exec 程序以
kapacitor
用户身份运行,该用户通常只具有对默认系统$PATH
的访问权限。如果使用不在$PATH
中的可执行文件,请传递可执行文件的绝对路径。
Execute an external program from a TICKscript
以下 TICKscript 在空闲 CPU 使用率降至 10% 以下时,使用 .exec()
事件处理程序执行 sound-the-alarm.py
Python 脚本。
exec-cpu-alert.tick
stream
|from()
.measurement('cpu')
|alert()
.crit(lambda: "usage_idle" < 10)
.exec('/usr/bin/python', 'sound-the-alarm.py')
Execute an external program from a defined handler
以下设置向 cpu
topic 发送警报,消息为“Hey, check your CPU”。添加了一个 exec handler,它订阅 cpu
topic 并在发布警报消息时执行 sound-the-alarm.py
Python 脚本。
创建一个 TICKscript,将警报消息发布到 topic。下面的 TICKscript 在空闲 CPU 使用率降至 10% 以下时,向 cpu
topic 发送警报消息。
cpu_alert.tick
stream
|from()
.measurement('cpu')
|alert()
.crit(lambda: "usage_idle" < 10)
.message('Hey, check your CPU')
.topic('cpu')
Add and enable the TICKscript
kapacitor define cpu_alert -tick cpu_alert.tick
kapacitor enable cpu_alert
创建一个 handler 文件,它订阅 cpu
topic 并使用 exec 事件处理程序来执行 sound-the-alarm.py
Python 脚本。
exec_cpu_handler.yaml
id: exec-cpu-alert
topic: cpu
kind: exec
options:
prog: '/usr/bin/python'
args:
- 'sound-the-alarm.py'
Add the handler
kapacitor define-topic-handler exec_cpu_handler.yaml
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Kapacitor and this documentation. To find support, use the following resources