Expose ClickHouse server metrics
If you’re using ClickHouse Cloud, you can expose metrics to Prometheus using the Prometheus Integration.
<prometheus.handlers> can be used to make more extended handlers on the same port.
This section is similar to <http_handlers> but works for prometheus protocols:
Check the endpoint:
Prometheus HTTP API and PromQL
ClickHouse implements the Prometheus HTTP API over aTimeSeries table. One handler serves remote write, remote read, instant PromQL queries, and range PromQL queries.
Prerequisites
Enable theallow_experimental_time_series_table setting for the user that creates and accesses the table:
TimeSeries table:
allow_experimental_time_series_table in the profile of the API user.
Configure the Prometheus API
Configure one prefix-routed handler on the main ClickHouse HTTP port:<defaults/> preserves the built-in handlers for endpoints such as /ping and for SQL requests. The prefix above exposes these endpoints through one handler:
The example omits
database and table from the handler. Each request must provide the table query parameter. It can also provide database, use a qualified table name such as prometheus.metrics, or omit the database to use default. This allows one handler to serve multiple TimeSeries tables.
To use one fixed table for every request, configure it in the handler:
Ingest metrics with remote write
ClickHouse supports the Prometheus remote-write protocol. Configure Prometheus to write to the handler:prometheus.metrics table.
Query with PromQL
Use the instant-query endpoint to evaluate a PromQL expression at one point in time:promql dialect, and the table functions.
Grafana
Configure a Prometheus data source with the base URL ending before/api/v1:
/api/v1/query or /api/v1/query_range to this base URL and adds customQueryParameters to each request.
Only the query endpoints
/api/v1/query and /api/v1/query_range are implemented. The metadata endpoints a Grafana Prometheus datasource uses for label browsing, template variables, and query-builder autocomplete (/api/v1/series, /api/v1/labels, /api/v1/label/<name>/values) are not implemented and return an error. Write PromQL expressions in code mode instead of the query builder.SQL entry points
ClickHouse uses the same PromQL converter for the HTTP API, thepromql dialect, and the prometheusQuery and prometheusQueryRange table functions.
Run PromQL directly with clickhouse-client:
Read metrics with remote read
ClickHouse supports the Prometheus remote-read protocol at/prometheus/api/v1/read.
Configure a Prometheus server to read from the same TimeSeries table: