Documentation

创建任务

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

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

在InfluxDB UI中创建任务

InfluxDB 用户界面提供多种创建任务的方法:

从数据探索器创建任务

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

  2. 构建一个查询并点击右上角的 另存为

  3. 选择任务标题。

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

  5. 点击 另存为任务

在任务用户界面中创建任务

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

  2. 点击 创建任务 在右上角。

  3. 在左侧面板中,指定任务选项。 查看 任务选项 以获取有关每个选项的详细信息。

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

    省略选项任务分配

    在InfluxDB任务用户界面创建一个任务时,请保持代码编辑器为空。 当您保存任务时,任务用户界面会使用您在任务选项表单中指定的任务选项为您填充option task = {task_options}

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

  5. 点击保存在右上角。

导入任务

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

  2. 点击 创建任务 在右上角。

  3. 在左侧面板中,指定任务选项。 查看 任务选项 以获取每个选项的详细信息。

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

  5. 点击 保存 在右上角。

从模板创建任务

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

  2. 找到您想使用的模板,然后点击其 Resources 列表以展开资源列表。

  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请求中提供以下内容:

请求头
  • 内容类型: application/json
  • 授权: 令牌 INFLUX_API_TOKEN
请求体

具有以下字段的JSON对象:

  • flux: 原始 Flux 任务字符串,包含一个 task 选项 和一个查询。
  • orgID: 你的 InfluxDB 组织 ID
  • 状态: 任务状态(“活动”或“非活动”)
  • 描述: 任务描述
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 开源版本现已公开Alpha测试

InfluxDB 3 Open Source is now available for alpha testing, licensed under MIT or Apache 2 licensing.

我们将发布两个产品作为测试版的一部分。

InfluxDB 3 核心,是我们新的开源产品。 它是一个用于时间序列和事件数据的实时数据引擎。 InfluxDB 3 企业版是建立在核心基础之上的商业版本,增加了历史查询能力、读取副本、高可用性、可扩展性和细粒度安全性。

有关如何开始的更多信息,请查看: