# 🚀 ClickHouse Setup with Prometheus and Grafana Monitoring

Monitoring isn’t optional when you’re running **ClickHouse** in production.

As developers, we’ve all been there:

* Queries suddenly slow down
    
* Disk fills up overnight
    
* Background merges eat up CPU
    
* And worst of all — you only find out after users complain
    

That’s exactly why I built the [**ClickHouse Monitoring Stack**](https://github.com/Ajinkgupta/clickhouse-monitoring-stack) — a single script that gets you **ClickHouse + Prometheus + Grafana** up and running in minutes.

In this blog, we’ll walk through why monitoring matters, what the stack includes, and how you can get it running on your own server.

---

## 🔑 Why Should Developers Care About Monitoring ClickHouse?

ClickHouse is insanely fast, but without visibility, you’re just guessing when things break. Here’s what proper monitoring gives you:

* **Query Insights** → Track slow queries & optimize them before users notice.
    
* **Resource Metrics** → Watch CPU, memory, and disk I/O usage.
    
* **Cluster Health** → Replication lag, node availability, and shard balance.
    
* **Alerts** → Know when something’s wrong *before* production explodes.
    

In short: **Monitoring turns chaos into control.**

---

## 🛠️ What’s Inside the Stack?

| Component | Port | Purpose |
| --- | --- | --- |
| **ClickHouse** | 8123 | Database HTTP access |
| **Prometheus** | 9090 | Scrapes & stores metrics |
| **Grafana** | 3000 | Dashboards & alerts |
| **CH Exporter** | 9363 | Exposes ClickHouse metrics |

This script installs everything automatically — no manual configs required.

---

## ⚡ Installation Guide (Hands-On)

1. **Clone the repo**
    
    ```bash
    git clone https://github.com/Ajinkgupta/clickhouse-monitoring-stack.git
    cd clickhouse-monitoring-stack
    ```
    
2. **Make the script executable**
    
    ```bash
    chmod +x setup.sh
    ```
    
3. **Run the installer**
    
    ```bash
    sudo ./setup.sh
    ```
    
4. **Enter your ClickHouse credentials** when prompted.
    

That’s it. The script handles installation, Prometheus config, and Grafana setup automatically.

---

## 📊 Access Your Monitoring Tools

* **Grafana** → `http://<server_ip>:3000` (login: `admin / admin`)
    
* **Prometheus** → `http://<server_ip>:9090`
    
* **ClickHouse HTTP** → `http://<server_ip>:8123`
    
* **Metrics Exporter** → `http://<server_ip>:9363/metrics`
    

---

## 🎨 Grafana Dashboards for Developers

1. Login to Grafana
    
2. Go to **Dashboards → Import**
    
3. Enter **ID: 14192** (popular ClickHouse dashboard)
    
4. Select Prometheus as datasource → Done ✅
    

Now you’ll see:

* Query latencies
    
* Insert/Select counts
    
* Disk usage growth
    
* Background merges & mutations
    
* Cluster replication lag
    

Perfect for devs debugging performance or scaling issues.

---

## 💡 Developer Best Practices

* **Set alerts** in Grafana → “Disk &gt; 80%” or “Query latency &gt; 2s”
    
* **Watch storage growth** → plan capacity before it’s too late
    
* **Monitor query mix** → SELECT vs INSERT balance matters
    
* **Integrate alerts** → Send them to Slack or PagerDuty
    

---

## 👨‍💻 About the Project

* Author: [Ajink Gupta](https://github.com/Ajinkgupta)
    
* Repo: [ClickHouse Monitoring Stack](https://github.com/Ajinkgupta/clickhouse-monitoring-stack)
    
* Contact: [ajink@duck.com](mailto:ajink@duck.com)
    

This project is **100% open source**. Fork it, improve it, and share feedback.

---

## 🎯 Final Thoughts

As developers, we spend too much time firefighting issues that proper monitoring could have prevented.

With this stack, you don’t have to waste hours setting up Prometheus and Grafana — just run one script and you’re done.

👉 Give it a try: [ClickHouse Monitoring Stack on GitHub](https://github.com/Ajinkgupta/clickhouse-monitoring-stack)
