TimeSeries table. One handler serves remote write, remote read, instant PromQL queries, and range PromQL queries.
To expose ClickHouse’s own metrics for a Prometheus server to scrape, see the Prometheus metrics endpoint.
Prerequisites
The setup steps differ between ClickHouse Cloud and self-managed ClickHouse. Follow the section for your deployment.ClickHouse Cloud
PromQL support in ClickHouse Cloud is in private preview. The services that take part in the private preview already have the
enable_time_series_table setting and the Prometheus API endpoints configured. Other ClickHouse Cloud services do not have this configuration, and you cannot enable the feature yourself on such a service. The SET enable_time_series_table statement and the http_handlers configuration in the next sections apply to self-managed deployments.Self-managed: enable the TimeSeries setting
Enable theenable_time_series_table setting for the user that creates and accesses the table:
enable_time_series_table in the profile of the API user.
Self-managed: configure the Prometheus API endpoints
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:
Create a TimeSeries table
Create a database and aTimeSeries table:
Ingest metrics with remote write
ClickHouse supports the Prometheus remote-write protocol. Configure Prometheus to write to the handler: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):
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: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:
/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, thepromql dialect, and the prometheusQuery and prometheusQueryRange table functions.
Run PromQL directly with clickhouse-client:
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: