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.
| Job | Targets | Labels |
|---|---|---|
clickhouse | :9363 to :9366 | node, shard |
clickhouse-keeper | :9371 to :9373 | member |
clickhouse-haproxy | :8405 | proxy |
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.
InsertedRows is counted where the part is written: a shard replica,
not the node that received the Distributed INSERT. Sum across nodes for
the cluster's rate.
Alerts
In prometheus/config/rules/alerts.yml, group clickhouse:
| Alert | Fires when | Why it matters |
|---|---|---|
ClickHouseDown | a node's /metrics is unreachable 1 m | one replica left for that shard |
ClickHouseShardDown | both replicas of a shard down 30 s | cluster queries fail (code 279) |
ClickHouseReadonlyReplica | ReadonlyReplica > 0 for 1 m | no Keeper session: inserts hang 142.8 s then fail |
ClickHouseKeeperNoLeader | no Keeper reports leader 30 s | replicated inserts and ON CLUSTER DDL stop |
ClickHouseKeeperMemberDown | a Keeper down 1 m | one more failure loses the majority |
ClickHouseReplicationLag | a replica over 300 s behind for 5 m | stale reads, slow recovery |
ClickHouseTooManyParts | over 500 parts in a partition for 5 m | inserts are delayed at 1,000 |
ClickHouseInsertsRejected | any rejected insert in 5 m | "Too many parts": writes are failing |
ClickHouseDistributedQueueBacklog | over 100 queued files for 10 m | rows invisible, and only on one disk |
ClickHouseMemoryNearLimit | over 70% of the container limit for 5 m | the server refuses allocations at 80% |
ClickHouseHAProxyBackendDown | fewer than 4 nodes in rotation 1 m | lost 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
SUCCESSThen 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 ClickHouseHAProxyBackendDownThe 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.