告别数据孤岛:Telegraf-loTDB 实现一站式监控数据闭环

Telegraf-IoTDB 无缝集成,有效消除数据孤岛,保障时序数据实时监控。

数据是驱动数字化转型的核心燃料,面对海量设备传感器持续生成的庞大时序数据,如何无缝实现高效采集、写入与存储,是工业物联网智能化领域的核心挑战。

Apache IoTDB 作为国产原生时序数据库,为工业物联网场景提供了低成本、高可用的时序数据管理能力。而 Telegraf 作为 InfluxData 开源的轻量级数据采集代理工具,支持多类数据源无缝接入,成为设备数据采集的关键枢纽。

Telegraf-IoTDB 集成插件成功建立物联网数据高效“运输”链路,方便用户收集、组织和处理海量高频时序数据,为实现多维系统监控提供稳定支撑:

  • 多源采集:支持多种输入、输出和处理器插件,配置方便,可以从不同来源收集数据,并发送至指定的数据库目标。

  • 高吞吐写入:支持千万级/秒数据写入性能,海量时序数据毫秒级接入,无惧弱网乱序数据困扰。

  • 低成本存储:基于为时序数据量身定制的文件格式 TsFile 与多类先进编码、压缩技术,实现 10X 倍无损压缩比,在不影响数据准确性的前提下节省空间占用。

欢迎查看用户手册了解更多详细内容!

01 功能简介

Telegraf 是一个开源代理工具,用于收集、处理和传输度量数据,由 InfluxData 开发。

Telegraf 有以下特点:

  • 插件体系结构:Telegraf 的强大之处在于其广泛的插件生态系统。它支持多种输入、输出和处理器插件,可以与各种数据源和目标无缝集成。

    • 数据收集:Telegraf 擅长从不同来源收集度量数据,例如系统指标、日志、数据库等。其多功能性使其适用于监视应用程序、基础架构和物联网设备。

    • 输出目标:一旦收集到数据,可以将其发送到各种输出目标。这种灵活性使 Telegraf 适应不同的监视和分析设置。

  • 配置简易:Telegraf 的配置使用 TOML 文件进行。这种简单性使用户能够轻松定义输入、输出和处理器,使定制变得简单明了。

  • 社区与支持:作为开源项目,Telegraf 受益于活跃的社区。用户可以通过论坛和文档贡献插件、报告问题并寻求帮助。

Telegraf-IoTDB 插件可以将保存在 Telegraf 中的监控信息输出存储到 IoTDB,输出插件使用了 IoTDB session 进行连接和数据写入。

telegraf集成图1-20250408.png

02 安装步骤

Telegraf 支持多种操作系统,包括 Linux、Windows、macOS,Telegraf 的安装推荐使用 root 管理员权限才能成功完成,具体安装要求及安装步骤请查看 InfluxData 官网:https://docs.influxdata.com/telegraf/v1/install/

  • 注:此插件为 Telegraf 内置插件,无需进行二次安装。

03 使用说明

设置输入源

在“telegraf.conf”配置文件中找到“INPUT PLUGINS”配置输入源,具体配置内容如下表所示:

telegraf集成图2-20250408.pngtelegraf集成图3-20250408.png

设置输出源

在“telegraf.conf”配置文件中找到“outputs.iotdb”配置输出源,具体配置内容如下表所示:

telegraf集成图4-20250408.pngtelegraf集成图5-20250408.png

*输入源示例可查看 InfluxData 官网。

启动 Telegraf 服务

telegraf -config /path/to/telegraf.conf

04 应用场景

可集成 Telegraf-IoTDB 插件的应用场景包括但不限于:

1. 物联网实时监控:利用 Telegraf-IoTDB 插件从各种物联网设备收集传感器上报的时序数据,并将其保存在 IoTDB 后端,从而实现对温度和湿度等环境条件的实时监控。同时,利用 IoTDB 的高效存储和查询功能,用户可以方便地分析随时间变化的数据趋势,并根据历史数据做出明智的决策。

2. 智慧农业数据采集:使用 Telegraf-IoTDB 插件收集智慧农业传感器上报的时序数据。通过将水分含量、养分含量和大气条件等指标传输到 IoTDB,农民能够得到最适配的种植、浇水时间规划,从而提高作物产量和资源管理效能。

3. 能源消耗分析:利用 Telegraf-IoTDB 插件实现对整个公用事业网络中智能电表能耗指标的全方位跟踪。集成 Telegraf-IoTDB 插件不仅能够精准识别用电高峰,还能运用分析模型,预测未来的能耗消费趋势,最终帮助相关部门有效建立节能计划并改善公用事业管理模式。

4. 自动化工业设备监控:使用 Telegraf-IoTDB 插件采集制造厂机器的各项运行指标,并将其存储在 IoTDB 中以供分析。基于此项集成,可以帮助识别机器运行的低效环节,判断预测性维护需求,实时监测运行异常,确保机器处于最佳运行性能状态,并最大限度地减少意外停机时间。

05 使用示例

以下是一个使用 Telegraf 收集 CPU 数据并使用 Telegraf-IoTDB 输出到 IoTDB 的示例。使用 Telegraf 命令生成配置文件:

telegraf --sample-config --input-filter cpu --output-filter iotdb > cpu_iotdb.conf

1. 在 cpu_iotdb.conf 中修改 input cpu 插件的配置。其中,“name_override” 字段为输出到 IoTDB 时使用的自定义时间序列路径名:

# Read metrics about cpu usage
[[inputs.cpu]]
  ## Whether to report per-cpu stats or not
  percpu = true
  ## Whether to report total system cpu stats or not
  totalcpu = true
  ## If true, collect raw CPU time metrics
  collect_cpu_time = false
  ## If true, compute and report the sum of all non-idle CPU states
  report_active = false
  ## If true and the info is available then add core_id and physical_id tags
  core_tags = false
  name_override = "root.demo.telgraf.cpu"

2. 在 cpu_iotdb.conf 中修改 output iotdb 插件的配置:

telegraf集成图4-20250408.png

# Save metrics to an IoTDB Database
[[outputs.iotdb]]
  ## Configuration of IoTDB server connection
  host = "127.0.0.1"
  # port = "6667"

  ## Configuration of authentication
  # user = "root"
  # password = "root"

  ## Timeout to open a new session.
  ## A value of zero means no timeout.
  # timeout = "5s"

  ## Configuration of type conversion for 64-bit unsigned int
  ## IoTDB currently DOES NOT support unsigned integers (version 13.x).
  ## 32-bit unsigned integers are safely converted into 64-bit signed integers by the plugin,
  ## however, this is not true for 64-bit values in general as overflows may occur.
  ## The following setting allows to specify the handling of 64-bit unsigned integers.
  ## Available values are:
  ##   - "int64"       --  convert to 64-bit signed integers and accept overflows
  ##   - "int64_clip"  --  convert to 64-bit signed integers and clip the values on overflow to 9,223,372,036,854,775,807
  ##   - "text"        --  convert to the string representation of the value
  # uint64_conversion = "int64_clip"

  ## Configuration of TimeStamp
  ## TimeStamp is always saved in 64bits int. timestamp_precision specifies the unit of timestamp.
  ## Available value:
  ## "second", "millisecond", "microsecond", "nanosecond"(default)
  timestamp_precision = "millisecond"

  ## Handling of tags
  ## Tags are not fully supported by IoTDB.
  ## A guide with suggestions on how to handle tags can be found here:
  ##     https://iotdb.apache.org/UserGuide/Master/API/InfluxDB-Protocol.html
  ##
  ## Available values are:
  ##   - "fields"     --  convert tags to fields in the measurement
  ##   - "device_id"  --  attach tags to the device ID
  ##
  ## For Example, a metric named "root.sg.device" with the tags `tag1: "private"`  and  `tag2: "working"` and
  ##  fields `s1: 100`  and `s2: "hello"` will result in the following representations in IoTDB
  ##   - "fields"     --  root.sg.device, s1=100, s2="hello", tag1="private", tag2="working"
  ##   - "device_id"  --  root.sg.device.private.working, s1=100, s2="hello"
  # convert_tags_to = "device_id"
   ## Handling of unsupported characters
  ## Some characters in different versions of IoTDB are not supported in path name
  ## A guide with suggetions on valid paths can be found here:
  ## for iotdb 0.13.x           -> https://iotdb.apache.org/UserGuide/V0.13.x/Reference/Syntax-Conventions.html#identifiers
  ## for iotdb 1.x.x and above  -> https://iotdb.apache.org/UserGuide/V1.3.x/User-Manual/Syntax-Rule.html#identifier
  ##
  ## Available values are:
  ##   - "1.0", "1.1", "1.2", "1.3"  -- enclose in `` the world having forbidden character
  ##                                    such as @ $ # : [ ] { } ( ) space
  ##   - "0.13"                      -- enclose in `` the world having forbidden character
  ##                                    such as space
  ##
  ## Keep this section commented if you don't want to sanitize the path
  sanitize_tag = "1.3"

3. 使用 cpu_iotdb.conf 配置文件运行 Telegraf,运行一段时间后,可以在 IoTDB 中查询到 Telegraf 收集上报的数据。

更多内容推荐:

下载时序数据库 IoTDB 开源版

• 了解如何使用 Telegraf-IoTDB 集成