diff --git a/receiver/chstatsreceiver/README.md b/receiver/chstatsreceiver/README.md index 739bcd2..71855cf 100644 --- a/receiver/chstatsreceiver/README.md +++ b/receiver/chstatsreceiver/README.md @@ -1,17 +1,28 @@ # Clickhouse Statistics Receiver -| Status | | -| ------------------------ |---------| -| Stability | [beta] | -| Supported pipeline types | metrics | +| Status | | +| ------------------------ |----------------| +| Stability | [beta] | +| Supported pipeline types | metrics, logs | + +The chstatsreceiver module is a component of the OpenTelemetry collector that collects and exports +metrics and logs from ClickHouse databases. + +It uses the ClickHouse Go client library to connect to the database and execute SQL queries +to retrieve metrics and log data. + +The module is designed to be highly configurable, allowing users to specify the database connection details, +the SQL queries to execute, and the metrics and logs to export. -The chstatsreceiver module is a component of the OpenTelemetry collector that collects and exports metrics from ClickHouse databases. It uses the ClickHouse Go client library to connect to the database and execute SQL queries to retrieve metrics data. The module is designed to be highly configurable, allowing users to specify the database connection details, the SQL queries to execute, and the metrics to export. ## Configuration - `dsn`: sets the Data Source Name (DSN) for the ClickHouse database. The DSN is a string that contains the necessary information to connect to the database, such as the host, port, and database name +- `type`: specifies the type of data to collect. Valid values are: + - `"metrics"`: collect metrics data (default if not specified) + - `"logs"`: collect log data - `queries`: list of the SQL queries that the receiver will execute against the database to retrieve metrics data. The queries are specified as a list of strings. - `timeout`: amount of time between two consecutive stats requests iterations. @@ -19,6 +30,7 @@ The timeout is specified as the duration value like `20s`, `1m`, etc. ## Clickhouse Queries +### For Metrics (type: "metrics") Each clickhouse query should return two fields: - labels as array of Tuple(String, String) - value Float64 @@ -32,12 +44,27 @@ SELECT 2::Float64 ``` +### For Logs (type: "logs") +Queries for logs should return two fields: +- labels as array of Tuple(String, String) +- message String + +The receiver will automatically convert the query results into log records. + +```sql +SELECT + [('level', 'debug'), ('label2', 'val2')]::Array(Tuple(String,String)), + 'log line to send' +``` + ## Example ```yaml receivers: - chstatsreceiver: + chstatsreceiver/metrics: dsn: clickhouse://localhost:9000 + type: metrics + timeout: 30s queries: - | SELECT [ @@ -47,13 +74,29 @@ receivers: FROM system.parts WHERE (active = 1) AND (database NOT IN ('system', '_system')) GROUP BY database, disk_name + chstatsreceiver/logs: + dsn: clickhouse://localhost:9000 + type: logs + timeout: 1m + queries: + - | + SELECT + [('job', 'clickhouse_query_logs')], + format('id={} query={}', query_id, query) + FROM system.query_id + WHERE event_time > now() - INTERVAL 1 MINUTE exporters: prometheusremotewrite: endpoint: http://localhost:3100/prom/remote/write timeout: 30s + loki: + endpoint: http://localhost:3100/loki/api/v1/push service: pipelines: metrics: - receivers: [chstatsreceiver] + receivers: [chstatsreceiver/metrics] exporters: [prometheusremotewrite] + logs: + receivers: [chstatsreceiver/logs] + exporters: [loki] ```