WAL 插件
示例 WAL 插件通过在 WAL(Write-Ahead Log,预写日志)刷新事件期间跟踪每个表的行数来监控 InfluxDB 3 中的数据写入操作。它会在 write_reports 表中创建摘要报告,以帮助分析数据摄取模式和速率。该插件还可以选择性地为指定的表双倍计算行数,以演示可配置的行为。
配置
可选参数
| 参数 | 类型 | 默认 | 描述 |
|---|---|---|---|
double_count_table | string | none | 要将写入报告中的行数双倍计算的表名(用于测试/演示) |
安装步骤
- 启用处理引擎来启动 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:来自触发器设置的配置参数
处理逻辑
- 遍历写入操作中的每个表批次
- 跳过
write_reports表以防止递归 - 计算每个批次的行数
- 如果
double_count_table匹配,则应用特殊处理 - 将报告记录写入
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 替换为你的 管理员令牌。
故障排除
常见问题
问题:未显示写入报告
解决方案:
- 验证触发器是否已成功创建
influxdb3 show summary --database DATABASE_NAME --token AUTH_TOKEN替换以下内容:
DATABASE_NAME:数据库的名称AUTH_TOKEN:您的令牌
- 检查除
write_reports以外的表是否实际写入了数据 - 查看日志以获取错误
问题:与 write_reports 无限递归
解决方案:这不应该发生,因为插件会自动跳过 write_reports 表,但如果你看到此问题
- 检查你是否已修改插件以移除跳过逻辑
- 验证表名比较是否正常工作
问题:行数似乎不正确
解决方案:
- 请记住,行数代表 WAL 刷新批次,而不是单个写入操作
- 多个写入操作可能在插件处理它们之前被批处理在一起
- 检查
double_count_table是否已设置并影响特定表
性能注意事项
- 此插件处理每个写入操作,因此它带来的开销极小
- 该插件每个 WAL 刷新批次每个表生成一次额外的写入
- 考虑高吞吐量系统对写入报告的存储影响
用例
- 写入监控:跟踪数据摄取模式和量
- 调试:识别哪些表正在接收写入
- 性能分析:监控写入批次大小和模式
- 数据验证:验证预期的写入量
- 测试:使用
double_count_table参数进行测试场景
报告问题
有关插件问题,请参阅插件存储库的 issues 页面。
查找 InfluxDB 3 Core 的支持
加入 InfluxDB Discord 服务器 是获取 InfluxDB 3 Core 和 InfluxDB 3 Enterprise 支持的最佳途径。对于其他 InfluxDB 版本,请参阅 支持和反馈 选项。
此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 InfluxDB 3 Core 和本文档提供反馈和错误报告。要获得支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。