Documentation

创建任务

使用 InfluxDB 用户界面 (UI)、influx 命令行界面 (CLI) 或 /api/v2 API 创建任务。

在创建任务之前,请查看编写任务的基础知识

在 InfluxDB UI 中创建任务

InfluxDB UI 提供了多种创建任务的方法

从数据浏览器创建任务

  1. 在左侧导航菜单中,选择 数据浏览器

  2. 构建查询,然后单击右上角的 另存为

  3. 选择 任务 标题。

  4. 指定任务选项。有关每个选项的详细信息,请参阅任务选项

  5. 单击 另存为任务

在任务 UI 中创建任务

  1. 在左侧导航菜单中,选择 任务

  2. 单击右上角的 创建任务

  3. 在左侧面板中,指定任务选项。有关每个选项的详细信息,请参阅任务选项

  4. 在右侧面板中,输入您的任务脚本。

    忽略 option tasks 分配

    在 InfluxDB 任务 UI 中创建任务时,请将代码编辑器留空。当您保存任务时,任务 UI 将使用您在 任务选项 表单中指定的任务选项为您填充 option task = {task_options}

    当您编辑已保存的任务时,您将看到注入的 option task = {task_options}

  5. 单击右上角的 保存

导入任务

  1. 在左侧导航菜单中,选择 任务

  2. 单击右上角的 创建任务

  3. 在左侧面板中,指定任务选项。有关每个选项的详细信息,请参阅任务选项

  4. 将原始 Flux 任务粘贴到任务选项字段右侧的代码编辑器中。

  5. 单击右上角的 保存

从模板创建任务

  1. 在左侧导航菜单中,选择 设置 > 模板

  2. 找到要使用的模板,然后单击其 资源 列表以展开资源列表。

  3. 资源 列表中,单击要使用的任务。

克隆任务

  1. 在左侧导航菜单中,选择 任务

  2. 找到您要克隆的任务,然后单击位于任务名称最右侧的 图标。

  3. 单击 克隆

使用 influx CLI 创建任务

使用 influx task create 命令创建新任务。它接受文件路径或原始 Flux。

使用文件创建任务

# Syntax
influx task create --org <org-name>  -f </path/to/task-script>

# Example
influx task create --org my-org -f /tasks/cq-mean-1h.flux

使用原始 Flux 创建任务

influx task create --org my-org - # <return> to open stdin pipe

option task = {
  name: "task-name",
  every: 6h
}

# ... Task script ...

# Linux & macOS: <ctrl-d> to close the pipe and submit the command
# Windows: <enter>, then <ctrl-d>, then <enter> to close the pipe and submit the command

使用 InfluxDB API 创建任务

使用 /api/v2/tasks InfluxDB API 端点 创建任务。

POST http://localhost:8086/api/v2/tasks/

在您的 API 请求中提供以下内容

请求标头
  • Content-Type: application/json
  • Authorization: Token INFLUX_API_TOKEN
请求正文

具有以下字段的 JSON 对象

  • flux: 原始 Flux 任务字符串,其中包含 task 选项 和查询。
  • orgID: 您的 InfluxDB 组织 ID
  • status: 任务状态(“active”或“inactive”)
  • description: 任务描述
curl --request POST 'http://localhost:8086/api/v2/tasks' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Token INFLUX_API_TOKEN' \
  --data-raw '{
    "flux": "option task = {name: \"CPU Total 1 Hour New\", every: 1h}\n\nfrom(bucket: \"telegraf\")\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\", org: \"INFLUX_ORG\")",
    "orgID": "INFLUX_ORG_ID",
    "status": "active",
    "description": "This task downsamples CPU data every hour"
}'

此页内容是否对您有帮助?

感谢您的反馈!


Flux 的未来

Flux 即将进入维护模式。您可以继续像目前一样使用它,而无需更改任何代码。

阅读更多

现已全面上市

InfluxDB 3 Core 和 Enterprise

快速启动。更快扩展。

获取更新

InfluxDB 3 Core 是一个开源、高速、近实时数据引擎,可实时收集和处理数据,并将其持久存储到本地磁盘或对象存储。InfluxDB 3 Enterprise 构建在 Core 的基础上,增加了高可用性、读取副本、增强的安全性以及数据压缩,从而实现更快的查询和优化的存储。InfluxDB 3 Enterprise 的免费层可供非商业家庭或业余爱好者使用。

有关更多信息,请查看