ClickHouse: read-only user setup
What we scrape: Query throughput, merge backlog, replica lag, parts per partition, mark cache hit-rate, memory & disk usage from the native `:9363/metrics` endpoint.
The official [ClickHouse Prometheus integration](https://clickhouse.com/docs/interfaces/prometheus) exposes metrics on a separate HTTP server (default port 9363) that does NOT use the ClickHouse user database — there is no exporter user to create, and ClickHouse itself does not provide native authentication on that port. Your job is to enable the endpoint and restrict who can reach it. The agent scrapes the URL you paste into the Add Exporter form; network reachability is the only authorization on the path.
1. Enable the Prometheus endpoint
Drop this file into `/etc/clickhouse-server/config.d/prometheus.xml` and restart ClickHouse. The endpoint then serves Prometheus exposition format at `http://<host>:9363/metrics`, sourced from `system.metrics`, `system.events`, and `system.asynchronous_metrics`.
XML<clickhouse> <prometheus> <endpoint>/metrics</endpoint> <port>9363</port> <metrics>true</metrics> <events>true</events> <asynchronous_metrics>true</asynchronous_metrics> <errors>true</errors> </prometheus> </clickhouse>2. Restrict who can reach :9363
The endpoint is unauthenticated by design — there is no user/password to set. Limit network reachability instead: bind to a private interface, allow the agent's egress IP through your firewall, or front it with a reverse proxy that enforces mTLS.
YAML# Example: kubernetes NetworkPolicy that lets ONLY the # monitor-agent namespace reach the ClickHouse metrics port. apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: clickhouse-metrics-from-agent-only spec: podSelector: matchLabels: app: clickhouse policyTypes: [Ingress] ingress: - from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: monitor-agent ports: - port: 9363 protocol: TCP3. Verify the endpoint serves metrics
From a host that is allowed by your firewall / NetworkPolicy, confirm the agent will see the metrics it expects.
bashcurl -sS "http://CLICKHOUSE_HOST:9363/metrics" \ | head -n 20
Because the agent never logs into ClickHouse itself, no DB user needs to be created or rotated. Rotating the agent's API key (in `/profile`) is enough to revoke its access.