Files
DBLog/config.yaml
QClaw Bot ebc1a2a87c fix: 替换所有中文括号为英文括号
feat: 新增操作审计字段 user/action/target/result 到 syslog 输出
docs: 更新 README 输出格式和配置示例说明
2026-05-13 13:33:45 +08:00

143 lines
4.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ==============================================================================
# db_log_exporter — 配置文件示例
# ==============================================================================
# 路径: /etc/db_log_exporter/config.yaml
# ==============================================================================
# 修改说明:
# 1. 在 databases 节点下定义各数据库连接信息
# 2. 在 sources 节点下定义需要导出的日志表
# 3. 每个 source 通过 database 字段引用一个已定义的数据库
# ==============================================================================
# ---------------------------------------------------------------------------
# 全局配置
# ---------------------------------------------------------------------------
global:
# 日志输出目录(需有写入权限)
output_dir: /var/log/db_exporter
# 断点存放目录(需有写入权限)
# 每次拉取后保存最后一条记录的 ID实现断点续传
checkpoint_dir: /var/lib/db_exporter/checkpoints
# 本程序写入日志时使用的 hostname(出现在 syslog 行中)
# 不填则自动取系统 hostname
hostname: ""
# 全局默认轮询间隔(秒),单个 source 可单独覆盖
interval: 30
# 全局默认每次最多读取条数,单个 source 可单独覆盖
batch_size: 1000
# ---------------------------------------------------------------------------
# 数据库连接定义
# ---------------------------------------------------------------------------
databases:
# ---------- MySQL 示例 ----------
mysql_prod:
type: mysql
host: 192.168.1.100
port: 3306
user: log_reader
password: "your_password_here"
database: app_logs
charset: utf8mb4
# ---------- PostgreSQL 示例 ----------
pg_prod:
type: postgresql
host: 192.168.1.200
port: 5432
user: log_reader
password: "your_password_here"
dbname: app_logs
# ---------------------------------------------------------------------------
# 日志源定义(每个 source = 一个数据库表)
# ---------------------------------------------------------------------------
sources:
# -------------------------------
# MySQL 日志表 — 按 ID 自增主键
# -------------------------------
- name: mysql_access_log
# 引用上方定义的数据库
database: mysql_prod
# 要查询的表名
table: access_log
# 输出到 output_dir 中的文件名(支持子目录,如 "subdir/app.log")
log_file: mysql_access.log
# 此数据源的 app_name(出现在 syslog 行 <app_name>[<pid>])
app_name: access-log
# 此数据源的轮询间隔(秒),覆盖全局配置
interval: 15
# 每次最多读取条数,覆盖全局配置
batch_size: 500
# 列名映射(当数据库列名与默认值不同时使用)
columns:
id: id # 主键/自增列(必填,用于断点跟踪)
timestamp: created_at # 时间戳列(必填)
level: log_level # 日志级别列(必填,值如 INFO/ERROR/WARN)
message: msg # 日志内容列(必填)
# 以下为可选扩展字段,可在 syslog structured data 中体现
trace_id: trace_id
span_id: span_id
extra: extra_data
# 操作审计字段
user: user
action: action
target: target
result: result
# -------------------------------
# MySQL 日志表 — 错误日志
# -------------------------------
- name: mysql_error_log
database: mysql_prod
table: error_log
log_file: mysql_error.log
app_name: error-log
interval: 10
columns:
id: id
timestamp: created_at
level: level
message: message
trace_id: trace_id
# -------------------------------
# PostgreSQL 日志表 — 应用日志
# -------------------------------
- name: pg_app_log
database: pg_prod
table: application_logs
log_file: pg_app.log
app_name: pg-app
interval: 30
columns:
id: log_id
timestamp: logged_at
level: severity
message: content
logger: component
trace_id: trace_id
extra: metadata
# -------------------------------
# PostgreSQL 日志表 — 审计日志
# -------------------------------
- name: pg_audit_log
database: pg_prod
table: audit_log
log_file: pg_audit.log
app_name: pg-audit
interval: 60
columns:
id: audit_id
timestamp: happened_at
level: event_type
message: description