首页/数据/NoSQL 速查/InfluxDB 2.x 定时降采样任务
本包目录(322 条)

InfluxDB 2.x 定时降采样任务

Task 是 2.x 内置的定时 Flux 任务:用 option task 声明周期,每次执行读取上一窗口数据聚合并写入低精度 bucket,实现自动降采样。

NoSQL 速查数据更新于 2026-10-12
声明option task = {name: "cpu-downsample", every: 1h, offset: 5m}
逻辑from(高精度 bucket) |> range(start: -task.every) |> aggregateWindow(every: 1h, fn: mean) |> to(bucket: "downsampled")
管理influx task create/list/run;日志用 influx task log 查看

示例

示例
option task = {name: "cpu-downsample", every: 1h, offset: 5m}

from(bucket: "metrics")
  |> range(start: -task.every)
  |> filter(fn: (r) => r._measurement == "cpu")
  |> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
  |> to(bucket: "downsampled", org: "my-org")
写入 downsampled 的结果保留原测量与标签,同名时间点重复执行会覆盖为同样内容,任务重跑是幂等的。

易错点

  • range(start: -task.every) 只看过去一个周期,任务停摆后历史缺口不会自动补,恢复后要手工重算
  • 聚合结果直接 to 到低精度 bucket 时应统一去掉不需要的字段,避免放大存储

数据来源与参考

  • InfluxData Docs: Process data with tasks
  • InfluxData Docs: Downsample data
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌