文档文档

Exec 事件处理程序

exec 事件处理程序会执行一个外部程序。事件数据通过 STDIN 传递给进程。

选项

以下 exec 事件处理程序的选项可以在 handler 文件中设置,或者在使用 TICKscript 中的 .exec() 时设置。

名称类型描述
progstring要执行的程序的路径。
argsstring 列表程序的参数列表。

示例:处理程序文件

id: handler-id
topic: topic-name
kind: exec
options:
  prog: /path/to/executable
  args: 
    - 'executable arguments'

示例:TICKscript

|alert()
  // ...
  .exec('/path/to/executable', 'executable arguments')

使用 exec 事件处理程序

exec 事件处理程序可以在 TICKscripts 和 handler 文件中使用,以根据警报逻辑执行外部程序。

注意: Exec 程序以 kapacitor 用户身份运行,该用户通常只能访问默认的系统 $PATH。如果使用不在 $PATH 中的可执行文件,请传递可执行文件的绝对路径。

从 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')

从定义的 handler 执行外部程序

以下设置将一条消息“Hey, check your CPU”发送到 cpu 主题。添加了一个 exec handler,该 handler 订阅 cpu 主题,并在发布警报消息时执行 sound-the-alarm.py Python 脚本。

创建将警报消息发布到主题的 TICKscript。当空闲 CPU 使用率低于 10% 时,下面的 TICKscript 将警报消息发送到 cpu 主题。

cpu_alert.tick

stream
  |from()
    .measurement('cpu')
  |alert()
    .crit(lambda: "usage_idle" < 10)
    .message('Hey, check your CPU')
    .topic('cpu')

添加并启用 TICKscript

kapacitor define cpu_alert -tick cpu_alert.tick
kapacitor enable cpu_alert

创建一个订阅 cpu 主题的 handler 文件,并使用 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'

添加处理器

kapacitor define-topic-handler exec_cpu_handler.yaml

此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2