文档文档

更新 Kapacitor Flux 任务

使用 kapacitor CLIKapacitor HTTP API 更新 Kapacitor Flux 任务。

使用 kapacitor flux task update 命令更新 Kapacitor Flux 任务。请提供以下标志:

* 必需

  • * -i, --id: 任务 ID
  • --status: 更新后的任务状态(activeinactive
  • -f, --file: 更新后的 Flux 脚本文件路径

示例

更新 Flux 任务代码
kapacitor flux task update \
  --id 000x00xX0xXXx00 \
  --file /path/to/updated-task.flux
启用或禁用 Flux 任务
kapacitor flux task update \
  --id 000x00xX0xXXx00 \
  --status inactive

使用以下请求方法和端点来更新 Kapacitor Flux 任务。

PATCH /kapacitor/v1/api/v2/tasks/{taskID}

在请求中提供以下信息(* 必填

Headers

  • * Content-type: application/json

路径参数

  • * taskID: 要更新的任务 ID

请求主体

具有以下模式的 JSON 对象

  • cron: 覆盖 cron Flux 任务选项
  • description: 新的任务描述
  • every: 覆盖 every Flux 任务选项
  • flux: 新的 Flux 任务代码
  • name: 覆盖 name Flux 任务选项
  • offset: 覆盖 offset Flux 任务选项
  • status: 新的 Flux 任务状态(activeinactive

API 示例

以下示例使用了任务 ID 000x00xX0xXXx00

更新 Flux 任务代码
curl --request PATCH 'https://:9092/kapacitor/v1/api/v2/tasks/000x00xX0xXXx00' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "flux": "option task = {name: \"Updated task name\", every: 1h}\n\nhost = \"https://:8086\"\ntoken = \"\"\n\nfrom(bucket: \"db/rp\", host:host, token:token)\n\t|> range(start: -1h)\n\t|> filter(fn: (r) =>\n\t\t(r._measurement == \"cpu\"))\n\t|> filter(fn: (r) =>\n\t\t(r._field == \"usage_system\"))\n\t|> filter(fn: (r) =>\n\t\t(r.cpu == \"cpu-total\"))\n\t|> aggregateWindow(every: 1h, fn: max)\n\t|> to(bucket: \"cpu_usage_user_total_1h\", host:host, token:token)"
}'
启用或禁用 Flux 任务
curl --request PATCH 'https://:9092/kapacitor/v1/api/v2/tasks/000x00xX0xXXx00' \
  --header 'Content-Type: application/json' \
  --data-raw '{"status": "inactive"}'
覆盖 Flux 任务选项
curl --request PATCH 'https://:9092/kapacitor/v1/api/v2/tasks/000x00xX0xXXx00' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "every": "1d",
    "name": "New task name",
    "offset": "15m"
}'

此页面是否有帮助?

感谢您的反馈!


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