文档文档

加载目录服务

加载目录服务支持通过文件定义 Kapacitor 任务、模板和主题处理程序,这些定义将在启动时或向进程发送 SIGHUP 信号时加载。

配置

加载目录服务的配置在 Kapacitor 配置文件中的 [load] 部分进行指定。

[load]
 enabled = true
 dir="/path/to/directory"

dir 指定定义文件所在的目录。

该服务将尝试从三个子目录加载定义。

tasks 目录应包含任务 TICKscripts 和相关的模板化任务定义文件(YAML 或 JSON)。

templates 目录应包含模板化的 TICKscripts。

handlers 目录将包含 YAML 或 JSON 格式的主题处理程序定义。

任务

任务文件必须放置在加载服务目录的 tasks 子目录中。任务 TICKscripts 根据以下方案指定:

  • id - 文件名,不含 .tick 扩展名
  • type - 通过对任务的内省确定(stream 或 batch)
  • dbrp - 使用 dbrp 关键字后跟指定数据库和保留策略来定义

在以下示例中,TICKscript 将为 dbrp telegraf.autogen 创建一个名为 my_taskstream 任务。

// /path/to/directory/tasks/my_task.tick
dbrp "telegraf"."autogen"

stream
    |from()
        .measurement('cpu')
        .groupBy(*)
    |alert()
        .warn(lambda: "usage_idle" < 20)
        .crit(lambda: "usage_idle" < 10)
        // Send alerts to the `cpu` topic
        .topic('cpu')

任务模板

模板文件必须放置在加载服务目录的 templates 子目录中。任务模板根据以下方案定义:

  • id - 文件名,不含 tick 扩展名
  • type - 通过对任务的内省确定(stream 或 batch)
  • dbrp - 使用 dbrp 关键字后跟指定数据库和保留策略来定义

以下 TICKscript 示例将为 dbrp telegaf.autogen 创建一个名为 my_templatestream 模板。

// /path/to/directory/templates/my_template.tick
dbrp "telegraf"."autogen"

var measurement string
var where_filter = lambda: TRUE
var groups = [*]
var field string
var warn lambda
var crit lambda
var window = 5m
var slack_channel = '#alerts'

stream
    |from()
        .measurement(measurement)
        .where(where_filter)
        .groupBy(groups)
    |window()
        .period(window)
        .every(window)
    |mean(field)
    |alert()
         .warn(warn)
         .crit(crit)
         .slack()
         .channel(slack_channel)

模板化任务

模板化任务文件必须放置在加载服务目录的 tasks 子目录中。模板化任务根据以下方案定义:

  • id - 文件名,不含 yamlymljson 扩展名
  • dbrps - 如果模板中未指定,则必需
  • template-id - 必需
  • vars - 模板变量列表

在此示例中,模板化任务 YAML 文件为 dbrp telegraf.autogen 创建了一个名为 my_templated_taskstream 任务。

# /path/to/directory/tasks/my_templated_task.tick
dbrps:
  - { db: "telegraf", rp: "autogen"}
template-id: my_template
vars:
  measurement:
   type: string
   value: cpu
  where_filter:
   type: lambda
   value: "\"cpu\" == 'cpu-total'"
  groups:
   type: list
   value:
       - type: string
         value: host
       - type: string
         value: dc
  field:
   type: string
   value : usage_idle
  warn:
   type: lambda
   value: "\"mean\" < 30.0"
  crit:
   type: lambda
   value: "\"mean\" < 10.0"
  window:
   type: duration
   value : 1m
  slack_channel:
   type: string
   value: "#alerts_testing"

使用 JSON 也可以创建相同的任务,如下例所示:

{
  "dbrps": [{"db": "telegraf", "rp": "autogen"}],
  "template-id": "my_template",
  "vars": {
    "measurement": {"type" : "string", "value" : "cpu" },
    "where_filter": {"type": "lambda", "value": "\"cpu\" == 'cpu-total'"},
    "groups": {"type": "list", "value": [{"type":"string", "value":"host"},{"type":"string", "value":"dc"}]},
    "field": {"type" : "string", "value" : "usage_idle" },
    "warn": {"type" : "lambda", "value" : "\"mean\" < 30.0" },
    "crit": {"type" : "lambda", "value" : "\"mean\" < 10.0" },
    "window": {"type" : "duration", "value" : "1m" },
    "slack_channel": {"type" : "string", "value" : "#alerts_testing" }
  }
}

主题处理程序

主题处理程序文件必须放置在加载服务目录的 handlers 子目录中。

id: handler-id
topic: cpu
kind: slack
match: changed() == TRUE
options:
  channel: '#alerts'

此页面是否有帮助?

感谢您的反馈!


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