Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ClickHouse Sink

ClickHouse sink 用于将解析后的记录批量写入 ClickHouse 数据库,适合大规模日志分析和实时数据查询场景。

连接器定义

[[connectors]]
id = "clickhouse_sink"
type = "clickhouse"
allow_override = [
  "endpoint",
  "database",
  "table",
  "username",
  "password",
  "timeout_secs",
  "max_retries"
]

[connectors.params]
endpoint = "http://clickhouse-server:8123"
database = ""
table = ""
username = "${SEC_USERNAME}"
password = "${SEC_PASSWORD}"
timeout_secs = 30
max_retries = 3

可用参数

参数类型说明
endpointstringClickHouse 端点地址,格式:http://host:porthttps://host:port(必填)
databasestring目标数据库名称(必填)
tablestring目标表名称(必填)
usernamestring认证用户名(必填)
passwordstring认证密码(可选,默认为空)
timeout_secsint单次请求超时秒数(默认 30
max_retriesint写入失败重试次数(默认 3-1 表示无限重试)

配置示例

基础用法

version = "2.0"

[sink_group]
name = "clickhouse"
rule = ["*"]
batch_timeout_ms = 5000
parallel = 4

[[sink_group.sinks]]
name = "clickhouse_stream_load"
connect = "clickhouse_sink"

[sink_group.sinks.params]
endpoint = "http://localhost:8123"
database = "default"
table = "wp_nginx"
username = "${SEC_USERNAME}"
password = "${SEC_PASSWORD}"
timeout_secs = 30
max_retries = 3

HTTPS 连接

[sink_group.sinks.params]
endpoint = "https://clickhouse.example.com:8443"
database = "production"
table = "logs"
username = "${SEC_USERNAME}"
password = "${SEC_PASSWORD}"
timeout_secs = 60
max_retries = 5