创建任务
使用 InfluxDB 用户界面 (UI)、influx
命令行界面 (CLI) 或 /api/v2
API 创建任务。
在创建任务之前,请查看编写任务的基础知识。
在 InfluxDB UI 中创建任务
InfluxDB UI 提供了多种创建任务的方法
从数据浏览器创建任务
在左侧导航菜单中,选择 数据浏览器。
构建查询,然后单击右上角的 另存为。
选择 任务 标题。
指定任务选项。有关每个选项的详细信息,请参阅任务选项。
单击 另存为任务。
在任务 UI 中创建任务
在左侧导航菜单中,选择 任务。
单击右上角的 创建任务。
在左侧面板中,指定任务选项。有关每个选项的详细信息,请参阅任务选项。
在右侧面板中,输入您的任务脚本。
忽略 option tasks 分配
在 InfluxDB 任务 UI 中创建新任务时,请将代码编辑器留空。当您保存任务时,任务 UI 将使用您在 任务选项 表单中指定的任务选项为您填充
option task = {task_options}
。当您编辑已保存的任务时,您将看到注入的
option task = {task_options}
。单击右上角的 保存。
导入任务
在左侧导航菜单中,选择 任务。
单击右上角的 创建任务。
在左侧面板中,指定任务选项。有关每个选项的详细信息,请参阅任务选项。
将原始 Flux 任务粘贴到任务选项字段右侧的代码编辑器中。
单击右上角的 保存。
从模板创建任务
在左侧导航菜单中,选择 设置 > 模板。
找到要使用的模板,然后单击其 资源 列表以展开资源列表。
在 资源 列表中,单击要使用的任务。
克隆任务
在左侧导航菜单中,选择 任务。
找到您要克隆的任务,然后单击位于任务名称最右侧的 图标。
单击 克隆。
使用 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"
}'
此页内容是否对您有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一份子!我们欢迎并鼓励您提供关于 InfluxDB 和本文档的反馈和错误报告。要获得支持,请使用以下资源
拥有年度合同或支持合同的客户可以联系 InfluxData 支持。