---
name: clickhouse-observability
description: |-
  Monitor ClickHouse with Prometheus metrics, Grafana dashboards, system table
  queries, and alerting for query performance, merge health, and resource usage.
  Use when setting up ClickHouse monitoring, building Grafana dashboards, or
  configuring alerts for production ClickHouse deployments.
  Trigger with "clickhouse monitoring", "clickhouse metrics", "clickhouse Grafana",
  "clickhouse observability", "monitor clickhouse", "clickhouse Prometheus".
allowed-tools: Read, Write, Edit
version: 1.7.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - database
  - analytics
  - clickhouse
  - olap
compatibility: Designed for Claude Code
title: clickhouse-observability
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/alerting.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/alerting.md), [references/instrumentation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/instrumentation.md), [references/prometheus-grafana.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/prometheus-grafana.md), [references/system-tables.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/system-tables.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/clickhouse-observability`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/clickhouse-observability`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/clickhouse-observability`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/clickhouse-observability --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/clickhouse-observability --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# ClickHouse Observability

## Overview

Set up comprehensive monitoring for ClickHouse using built-in system tables,
Prometheus integration, Grafana dashboards, and alerting rules. The workflow
layers four signal sources: `system.*` tables (always available, zero
dependencies), a Prometheus scrape endpoint, application-level client
instrumentation, and alert rules that fire on the failure modes that actually
page an on-call — high error rate, latency creep, merge backlog, and resource
exhaustion.

Deep configs live in `references/` so this file stays a fast, followable map.

## Prerequisites

- ClickHouse instance with `system.*` table access
- Prometheus (or compatible: Grafana Alloy, Victoria Metrics)
- Grafana for dashboards
- AlertManager or PagerDuty for alerts

## Instructions

### Step 1: Query system tables for a health snapshot

Start with zero dependencies — the `system.*` tables already hold everything.
Run this for an instant server-health read:

```sql
SELECT
    (SELECT count() FROM system.processes) AS running_queries,
    (SELECT value FROM system.metrics WHERE metric = 'MemoryTracking') AS memory_bytes,
    (SELECT count() FROM system.merges) AS active_merges;
```

Query throughput, insert rates, and per-table part counts (the merge-health
signal), plus a full table of which `system.*` table to poll at what frequency:
[system table queries & reference](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/system-tables.md).

### Step 2: Wire up Prometheus scraping

ClickHouse Cloud exposes a managed Prometheus endpoint (Basic auth with a Cloud
API key); self-hosted uses the built-in `:9363` `/metrics` endpoint enabled in
`config.xml`. Write the scrape config to your `prometheus.yml`. Full Cloud +
self-hosted scrape configs and the `config.xml` block:
[Prometheus scrape config & Grafana dashboards](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/prometheus-grafana.md).

### Step 3: Instrument the application client

Server metrics show what ClickHouse does; client metrics attribute latency,
error codes, and insert volume to your own code. Wrap queries in a `prom-client`
histogram/counter and expose `/metrics`. Full instrumentation + structured
logging: [application-level instrumentation](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/instrumentation.md).

### Step 4: Build Grafana dashboard panels

Panels for QPS, P50/P95/P99 latency, error rate, and insert throughput are in
the [Grafana dashboards reference](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/prometheus-grafana.md). Or import
the official community dashboard: `https://grafana.com/grafana/dashboards/23415`.

### Step 5: Load alert rules

Write Prometheus alert rules for the five production failure modes (error rate,
latency, part count, memory, disk) to a rules file loaded by AlertManager. Full
rule set plus per-alert tuning notes: [Prometheus alert rules](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/alerting.md).

## Output

Applying this skill produces a set of monitoring config artifacts you write to
your infrastructure repo:

- `prometheus.yml` — scrape config targeting your ClickHouse endpoint
- `clickhouse-alerts.yml` — the five-rule alert group loaded by AlertManager
- A Grafana dashboard (imported ID `23415` or the custom JSON panels)
- Client instrumentation exposing `clickhouse_query_duration_seconds`,
  `clickhouse_query_errors_total`, and `clickhouse_insert_rows_total`
- Ad-hoc `system.*` queries for on-demand health snapshots

## Error Handling

| Issue | Cause | Solution |
|-------|-------|----------|
| Metrics endpoint empty | Prometheus not configured | Enable `/metrics` in config |
| High cardinality alerts | Too many label values | Reduce label cardinality |
| Missing query_log data | Logging disabled | Set `log_queries = 1` in config |
| Dashboard gaps | Scrape interval too long | Use 10-15s scrape interval |

## Examples

**Snapshot server health right now** — run the Step 1 query against any instance
with `system.*` access; no exporter or scrape needed. See
[system-tables.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/system-tables.md) for throughput and merge-health
variants.

**Alert when merges fall behind** — the `ClickHouseTooManyParts` rule fires when
a table exceeds 300 active parts for 10 minutes, the classic
inserts-outpacing-merges signal. Full rule + tuning guidance:
[alerting.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/alerting.md).

**Attribute slow queries to your service** — wrap calls in `instrumentedQuery()`
so P95 latency and error codes land in Prometheus labeled by query type. See
[instrumentation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/clickhouse-observability/references/instrumentation.md).

## Resources

- [Prometheus Integration](https://clickhouse.com/docs/integrations/prometheus)
- [ClickHouse Grafana Dashboard](https://grafana.com/grafana/dashboards/23415)
- [System Tables Reference](https://clickhouse.com/docs/operations/system-tables)
- [Cloud Monitoring](https://clickhouse.com/blog/clickhouse-cloud-now-supports-prometheus-monitoring)
- For incident response, see the `clickhouse-incident-runbook` skill.
