clickhouse-logger
Sends request logs to a ClickHouse table.
clickhouse-loggerPriority 398What it does
clickhouse-logger stores the records of the requests that reach the route or other object it is added to in a ClickHouse table, through the server's HTTP interface. The records are collected on the gateway node and sent in batches, each one an INSERT into the Logtable, so one statement can carry several records.
Under One address every batch goes to the Endpoint address, under Several addresses to one address of the list picked at random. Every address ends in its path, / for the server's root, or nothing is stored.
When to use it
- The analytics team keeps request records in ClickHouse and queries them with SQL beside the rest of the company's data.
- The orders API should write one row per request into the table
access_logof the databasegateway. - Several ClickHouse servers take records, and each batch may go to any one of them.
- Every route that stores its records in ClickHouse should write the same columns, the host, client, method, path, status and time, set once in the plugin metadata.
Not for records sent to an HTTP collector of your own — see http-logger (Sends request logs to an HTTP endpoint in batches), records kept in Elasticsearch — see elasticsearch-logger (Sends request logs to an Elasticsearch index) or records sent to a Kafka topic — see kafka-logger (Sends request logs to a Kafka topic).
Set it up
Store a record of each request in a ClickHouse table
The address ends in its path, / for the server's root; without one the gateway sends no request target and stores nothing. The password travels with every batch, so the address is the server's HTTPS port.
Under Basics choose One address, set Endpoint address to https://clickhouse.example.com:8443/, set Database to gateway, set Logtable to access_log, set User to gateway and set Password to <secret>.
{
"endpoint_addr": "https://clickhouse.example.com:8443/",
"database": "gateway",
"logtable": "access_log",
"user": "gateway",
"password": "<secret>"
}
More scenarios
Spread the records over several ClickHouse servers
Each address ends in its path, / for the server's root; without one the gateway sends no request target and stores nothing. The password travels with every batch, so the addresses are the servers' HTTPS port.
Under Basics choose Several addresses, fill Endpoint addresses as in the JSON below, set Database to gateway, set Logtable to access_log, set User to gateway and set Password to <secret>.
{
"endpoint_addrs": [
"https://10.0.4.21:8443/",
"https://10.0.4.22:8443/"
],
"database": "gateway",
"logtable": "access_log",
"user": "gateway",
"password": "<secret>"
}
Choose the fields every route that carries the plugin writes into its recordenvironment-wide settings
Fill Log format as in the JSON below.
{
"log_format": {
"host": "$host",
"client": "$remote_addr",
"method": "$request_method",
"uri": "$uri",
"status": "$status",
"at": "$time_iso8601"
}
}
Things to know
- Endpoint address — An address that stops at the port sends a request with no target, and nothing is stored. End it with
/for the server's root, as the example does. - Endpoint address — An address without its scheme,
127.0.0.1:8123for example, is refused when you save. - Endpoint addresses — Give either one address or a list, never both and never neither; either way the save is refused.
- Endpoint addresses — Every address must accept the same records: each batch goes to one of them at random.
- Logtable — Each batch arrives at the server as
INSERT INTO access_log FORMAT JSONEachRow, whereaccess_logis the table named here. - Logtable — The name is pasted into the INSERT the batch is sent as, so an empty one sends a statement with no table at all.
- A Log format in the plugin metadata gives the same record to every route whose clickhouse-logger names no Log format of its own. In the example each record carries
atwith the time of the request. - Log format extra — Added to the default record only: while a log format is set, on this object or in the plugin's metadata, the engine writes that format alone and reads nothing here.
- Timeout — A whole number of seconds, at least one:
0is refused when you save. - Include request body when — Not checked at save: an expression the engine cannot read is stored, and the body is then never logged. Only the gateway's error log says so.
- Include response body when — Not checked at save: an expression the engine cannot read is stored, and the body is then never logged. Only the gateway's error log says so.
- Batch size — A batch goes out when it holds Batch size records, when its first record has waited Buffer duration, or when nothing new arrived for Inactive timeout.
- In the plugin metadata, Pending entry limit caps the backlog. While more entries than this wait to be sent, new ones are dropped rather than queued.
- AdviceGive an
https://address whenever a Password is set, as the examples do. - AdviceTurn on the request and response bodies only on routes whose table may hold what clients and the backend send.
Settings
The fields as the console shows them, section by section.
Basics
Choose one:
One address
endpoint_addrstringRequiredThe address of the ClickHouse HTTP interface, ending with a path such as http://clickhouse.example.com:8123/. An address that stops at the port sends a request with no target, and nothing is stored.
pattern
^[^\/]+:\/\/([\da-zA-Z.-]+|\[[\da-fA-F:]+\])(:\d+)?https://clickhouse.example.com:8443/Several addresses
endpoint_addrsarray of stringsRequiredThe addresses of the ClickHouse HTTP interfaces, each ending with a path such as http://clickhouse.example.com:8123/. An address that stops at the port sends a request with no target, and nothing is stored.
databasestringdefault logtablestringdefault userstringdefault passwordstringdefault Stored on the engine and shown only to roles that manage this object.
Behavior
timeoutintegerdefault 3ssl_verifybooleandefault truelog_formatobject{"host":"$host","client":"$remote_addr","status":"$status","at":"$time_iso8601"}log_format_extraobject{"zone":"eu-west","gateway":"$hostname"}include_req_bodybooleandefault falseinclude_req_body_exprarrayinclude_resp_bodybooleandefault falseinclude_resp_body_exprarraymax_req_body_bytesintegerdefault 524288max_resp_body_bytesintegerdefault 524288Advanced
batch_max_sizeintegerdefault 1000buffer_durationintegerdefault 60inactive_timeoutintegerdefault 5max_retry_countintegerdefault 0retry_delayintegerdefault 1namestringdefault clickhouse-loggerEnvironment-wide settings
Set once per environment, under Plugins › clickhouse-logger. Every clickhouse-logger in the environment uses these.
log_formatobject{"host":"$host","client":"$remote_addr","status":"$status","at":"$time_iso8601"}log_format_extraobject{"zone":"eu-west","gateway":"$hostname"}max_pending_entriesintegerdefault 8192How many log entries may wait to be sent. While the backlog is above this number, new entries are dropped rather than queued.