Skip to main content

Expose ClickHouse server metrics

If you’re using ClickHouse Cloud, you can expose metrics to Prometheus using the Prometheus Integration.
Configure a dedicated port when a Prometheus server needs to scrape ClickHouse’s own metrics:
Section <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:
Settings: Check the endpoint:

Prometheus HTTP API and PromQL

ClickHouse implements the Prometheus HTTP API over a TimeSeries table. One handler serves remote write, remote read, instant PromQL queries, and range PromQL queries.

Prerequisites

Enable the allow_experimental_time_series_table setting for the user that creates and accesses the table:
Create a database and a TimeSeries table:
For HTTP API requests, enable 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 (except for /format_query, which only parses the given PromQL expression and doesn’t need a table). 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:
A table configured in the handler cannot be overridden by request parameters. Routing and handler settings:

Ingest metrics with remote write

ClickHouse supports the Prometheus remote-write protocol. Configure Prometheus to write to the handler:
Prometheus sends samples to the prometheus.metrics table. To batch data from many concurrent remote-write requests into fewer parts, enable asynchronous inserts by adding the async_insert setting to the URL (or by enabling it in the user profile):
ClickHouse acknowledges an asynchronous remote-write request only after the data is flushed to all inner tables of the TimeSeries table, regardless of the wait_for_async_insert setting: the remote-write protocol treats an acknowledged write as durable. If the flush fails, the request returns an error and Prometheus retries it.

Query with PromQL

Use the instant-query endpoint to evaluate a PromQL expression at one point in time:
Use the range-query endpoint to evaluate an expression over a time range:
Use the format-query endpoint to parse and format a PromQL expression without evaluating it:
The expression is returned serialized from the parsed query, with the whitespace normalized, the comments removed, the redundant parentheses dropped, and the durations converted to numbers of seconds: sum by (job) (http_requests_total{code="200"}) / 2. This endpoint doesn’t evaluate the expression, so it doesn’t need the database and table parameters. See the supported PromQL features for the function and aggregation operator list used by the HTTP API, the promql dialect, and the table functions.

Grafana

Configure a Prometheus data source with the base URL ending before /api/v1:
Grafana appends /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, /api/v1/query_range, and /api/v1/format_query and the metadata endpoints /api/v1/series, /api/v1/labels, /api/v1/label/<name>/values, and /api/v1/metadata are implemented. /api/v1/series requires at least one match[] series selector, supports the optional start, end, and limit parameters, and returns the union of the series matched by each selector. /api/v1/labels accepts the same parameters, with match[] being optional, and returns the sorted label names of the matched series (or of all series when no selectors are given). /api/v1/label/<name>/values accepts the same parameters as /api/v1/labels and returns the sorted values of one label, with <name> optionally using the Prometheus U__... escaping of label names that contain characters outside [a-zA-Z0-9_]. These endpoints cover what a Grafana Prometheus datasource uses for label browsing, template variables, and query-builder autocomplete.

SQL entry points

ClickHouse uses the same PromQL converter for the HTTP API, the promql dialect, and the prometheusQuery and prometheusQueryRange table functions. Run PromQL directly with clickhouse-client:
Use the table functions to embed PromQL in a SQL query:

Query metric metadata

The /prometheus/api/v1/metadata endpoint returns the metric metadata stored in the Metrics target table of the TimeSeries table: the type, help text, and unit of each metric family. It supports the following Prometheus parameters in the URL query string: The default Metrics target table is a ReplacingMergeTree ordered by the metric family name: it keeps the most recently written metadata entry for each metric family. Several entries per family are returned only while the target table stores them — before its parts are merged, or when the table is defined with an engine that preserves them.

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:
Last modified on August 30, 2026