Learn Labs
Monitoring & Operations

Cluster Monitoring: Metrics, Dashboard, Alerts

What Prometheus scrapes from the cluster, the Grafana dashboard, and alerts tested in promtool and by breaking the cluster

Every ClickHouse server and every Keeper serves Prometheus metrics itself (<prometheus> in config/server/server.xml and config/keeper/keeper.xml); HAProxy has a built-in exporter. No sidecar exporters are needed.

JobTargetsLabels
clickhouse:9363 to :9366node, shard
clickhouse-keeper:9371 to :9373member
clickhouse-haproxy:8405proxy

Metric names follow the system tables: ClickHouseMetrics_* is system.metrics (current values), ClickHouseProfileEvents_* is system.events (counters, use rate()), ClickHouseAsyncMetrics_* is system.asynchronous_metrics (sampled every second or so).

The dashboard

grafana/dashboards/Databases/clickhouse-overview.json ("ClickHouse Cluster"). The top row answers "is it healthy": nodes up, shards with a live replica, exactly one Keeper leader, Keeper members, read-only replicas, nodes in HAProxy's rotation. Below it: queries and failed queries per node, rows inserted, max parts per partition, replication delay and queue, the Distributed insert backlog, memory against the container limit, CPU, merges, delayed and rejected inserts, Keeper requests, and HAProxy sessions. Every panel's query was run against the live cluster and returns data.

Alerts

In prometheus/config/rules/alerts.yml, group clickhouse:

AlertFires whenWhy it matters
ClickHouseDowna node's /metrics is unreachable 1 mone replica left for that shard
ClickHouseShardDownboth replicas of a shard down 30 scluster queries fail (code 279)
ClickHouseReadonlyReplicaReadonlyReplica > 0 for 1 mno Keeper session: inserts hang 142.8 s then fail
ClickHouseKeeperNoLeaderno Keeper reports leader 30 sreplicated inserts and ON CLUSTER DDL stop
ClickHouseKeeperMemberDowna Keeper down 1 mone more failure loses the majority
ClickHouseReplicationLaga replica over 300 s behind for 5 mstale reads, slow recovery
ClickHouseTooManyPartsover 500 parts in a partition for 5 minserts are delayed at 1,000
ClickHouseInsertsRejectedany rejected insert in 5 m"Too many parts": writes are failing
ClickHouseDistributedQueueBacklogover 100 queued files for 10 mrows invisible, and only on one disk
ClickHouseMemoryNearLimitover 70% of the container limit for 5 mthe server refuses allocations at 80%
ClickHouseHAProxyBackendDownfewer than 4 nodes in rotation 1 mlost capacity

The unit tests in prometheus/config/tests/alerts.test.yml replay a shard going down, Keeper losing its leader with a replica going read-only, and a partition's parts climbing until inserts are rejected:

docker exec prometheus promtool test rules /etc/prometheus/tests/alerts.test.yml
SUCCESS

Then the real test: with Prometheus running, stopping ch-3, ch-4, keeper-2 and keeper-3 for 150 s fired exactly the alerts it should:

firing ClickHouseDown              ch-3 (shard 02)
firing ClickHouseDown              ch-4 (shard 02)
firing ClickHouseShardDown         shard 02
firing ClickHouseReadonlyReplica   ch-1, ch-2
firing ClickHouseKeeperNoLeader
firing ClickHouseKeeperMemberDown  keeper-2, keeper-3
firing ClickHouseHAProxyBackendDown

The read-only replicas are ch-1 and ch-2, the nodes that were still up: with Keeper gone, the surviving shard can read but can't write.

On this page