文档文档

WAL 插件

示例 WAL 插件通过在 WAL(Write-Ahead Log,预写日志)刷新事件期间跟踪每个表的行数来监控 InfluxDB 3 中的数据写入操作。它会在 write_reports 表中创建摘要报告,以帮助分析数据摄取模式和速率。该插件还可以选择性地为指定的表双倍计算行数,以演示可配置的行为。

配置

可选参数

参数类型默认描述
double_count_tablestringnone要将写入报告中的行数双倍计算的表名(用于测试/演示)

安装步骤

  1. 启用处理引擎来启动 InfluxDB 3 核心(--plugin-dir /path/to/plugins
    influxdb3 serve \
      --node-id node0 \
      --object-store file \
      --data-dir ~/.influxdb3 \
      --plugin-dir ~/.plugins

触发器设置

写入监控

监控所有表写入并生成写入报告

influxdb3 create trigger \
  --database monitoring \
  --plugin-filename examples/wal_plugin/wal_plugin.py \
  --trigger-spec "all_tables" \
  wal_monitoring

带有特殊处理的写入监控

监控写入,并对特定表进行特殊处理

influxdb3 create trigger \
  --database monitoring \
  --plugin-filename examples/wal_plugin/wal_plugin.py \
  --trigger-spec "all_tables" \
  --trigger-arguments 'double_count_table=temperature' \
  wal_monitoring_special

示例用法

示例:基本写入监控

设置写入监控以跟踪数据摄取

# Create the monitoring trigger
influxdb3 create trigger \
  --database testdb \
  --plugin-filename examples/wal_plugin/wal_plugin.py \
  --trigger-spec "all_tables" \
  write_monitor

# Write test data to various tables
influxdb3 write \
  --database testdb \
  "temperature,location=office value=22.5"
  
influxdb3 write \
  --database testdb \
  "humidity,location=office value=45.2"
  
influxdb3 write \
  --database testdb \
  "pressure,location=office value=1013.25"

# The plugin automatically generates write reports in the `write_reports` measurement.

# Query the write reports
influxdb3 query \
  --database testdb \
  "SELECT * FROM write_reports ORDER BY time DESC"

预期输出

table_name  | row_count | time
------------|-----------|-----
pressure    | 1         | 2024-01-01T12:02:00Z
humidity    | 1         | 2024-01-01T12:01:00Z
temperature | 1         | 2024-01-01T12:00:00Z

示例:带有特殊表处理的监控

监控写入,并对温度数据进行双倍计数

# Create trigger with special handling
influxdb3 create trigger \
  --database testdb \
  --plugin-filename examples/wal_plugin/wal_plugin.py \
  --trigger-spec "all_tables" \
  --trigger-arguments 'double_count_table=temperature' \
  write_monitor_special

# Write test data
influxdb3 write \
  --database testdb \
  "temperature,location=office value=22.5"
  
influxdb3 write \
  --database testdb \
  "humidity,location=office value=45.2"

# Query the write reports
influxdb3 query \
  --database testdb \
  "SELECT * FROM write_reports ORDER BY time DESC"

预期输出

table_name  | row_count | time
------------|-----------|-----
humidity    | 1         | 2024-01-01T12:01:00Z
temperature | 2         | 2024-01-01T12:00:00Z

注意:尽管只写入了 1 行,但温度表显示行数为 2,这演示了 double_count_table 参数。

生成的度量

write_reports

跟踪在 WAL 刷新事件期间写入每个表的行数。

标签

  • table_name:接收写入的表的名称

字段

  • row_count:此 WAL 刷新中写入的行数(整数)

特殊行为

  • 如果 double_count_table 参数匹配表名,行数将翻倍
  • 插件会自动跳过 write_reports 表,以避免无限递归

代码概述

文件

  • wal_plugin.py:处理写入批次并生成报告的主要插件代码

主函数

process_writes(influxdb3_local, table_batches, args)

处理写入批次的入口点。每次将数据写入数据库时都会调用。

参数

  • influxdb3_local:用于写入和日志记录的 InfluxDB 客户端
  • table_batches:包含已写入数据的表批次列表
  • args:来自触发器设置的配置参数

处理逻辑

  1. 遍历写入操作中的每个表批次
  2. 跳过 write_reports 表以防止递归
  3. 计算每个批次的行数
  4. 如果 double_count_table 匹配,则应用特殊处理
  5. 将报告记录写入 write_reports 度量

日志记录

日志存储在 _internal 数据库的 system.processing_engine_logs 表中。要查看日志

influxdb3 query \
  --database _internal \
  --token 
AUTH_TOKEN
\
"SELECT * FROM system.processing_engine_logs WHERE trigger_name = 'wal_monitoring'"

AUTH_TOKEN 替换为你的 管理员令牌

故障排除

常见问题

问题:未显示写入报告

解决方案:

  1. 验证触发器是否已成功创建
influxdb3 show summary --database 
DATABASE_NAME
--token
AUTH_TOKEN

替换以下内容:

  • DATABASE_NAME:数据库的名称
  • AUTH_TOKEN:您的令牌
  1. 检查除 write_reports 以外的表是否实际写入了数据
  2. 查看日志以获取错误

问题:与 write_reports 无限递归

解决方案:这不应该发生,因为插件会自动跳过 write_reports 表,但如果你看到此问题

  1. 检查你是否已修改插件以移除跳过逻辑
  2. 验证表名比较是否正常工作

问题:行数似乎不正确

解决方案:

  1. 请记住,行数代表 WAL 刷新批次,而不是单个写入操作
  2. 多个写入操作可能在插件处理它们之前被批处理在一起
  3. 检查 double_count_table 是否已设置并影响特定表

性能注意事项

  • 此插件处理每个写入操作,因此它带来的开销极小
  • 该插件每个 WAL 刷新批次每个表生成一次额外的写入
  • 考虑高吞吐量系统对写入报告的存储影响

用例

  • 写入监控:跟踪数据摄取模式和量
  • 调试:识别哪些表正在接收写入
  • 性能分析:监控写入批次大小和模式
  • 数据验证:验证预期的写入量
  • 测试:使用 double_count_table 参数进行测试场景

报告问题

有关插件问题,请参阅插件存储库的 issues 页面

查找 InfluxDB 3 Core 的支持

加入 InfluxDB Discord 服务器 是获取 InfluxDB 3 Core 和 InfluxDB 3 Enterprise 支持的最佳途径。对于其他 InfluxDB 版本,请参阅 支持和反馈 选项。


此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2