Files
2026-10-30 16:35:46 +02:00

112 lines
3.5 KiB
Markdown

# DB Monitor
> Monitor your PostgreSQL databases without the Prometheus + Grafana overhead.
A lightweight, self-hosted monitoring tool built with Go. Point it at your PostgreSQL instances, and it gives you a real-time dashboard with metrics, charts, and Telegram alerts — out of the box.
No config files to wrestle with. No YAML. Just set your connection string and go.
## Getting Started
### Option 1 — Docker Hub (recommended)
```bash
docker run -d \
--name db-monitor \
-p 9432:9432 \
-v db-monitor-data:/data \
-e DB_MONITOR_DSN="postgresql://user:pass@host:5432/mydb" \
mahmoudmo123/db-monitor:latest
```
Dashboard will be at `http://localhost:9432`.
### Option 2 — docker compose
```bash
git clone https://github.com/mahmoud/db-monitor.git
cd db-monitor
cp .env.example .env # add your PostgreSQL DSN here
docker compose up -d
```
Dashboard will be at `http://localhost:9432`.
### Option 3 — Ghaymah Cloud
1. Go to **deploy.ghaymah.systems** → **Deploy App**
2. **Container image:** `mahmoudmo123/db-monitor:latest`
3. **Port:** `9432`
4. **Environment variables** (optional):
| Key | Value |
|---|---|
| `DB_MONITOR_PORT` | `9432` |
| `DB_MONITOR_INTERVAL` | `15` |
| `DB_MONITOR_SQLITE_PATH` | `/data/db-monitor.db` |
5. **Volume:** mount `/data` for persistent storage
6. Click **Deploy App** ✅
> **Adding databases:** No need to set `DB_MONITOR_DSN` upfront. Once deployed, open the dashboard → **Settings** and add your PostgreSQL connections from the UI.
## What It Tracks
- **Connections** — active, idle, total, max, usage percentage
- **Queries** — currently running, long-running (>5min), waiting
- **Locks** — active, waiting, deadlocks
- **Performance** — cache hit ratio, commits/rollbacks, tuple operations
- **Replication** — lag, primary/replica status
- **Size & uptime** — database size, PostgreSQL version
## Alerting
If you configure Telegram, you get notified when things go wrong:
- Database goes **down**
- Connection usage exceeds **80%**
- A query runs longer than **5 minutes**
- **Deadlocks** detected
- More than **5 locks** waiting
- Cache hit ratio drops below **90%**
## Permissions
DB Monitor only needs read access. Create a dedicated user:
```sql
CREATE USER db_monitor WITH PASSWORD 'your_password';
GRANT CONNECT ON DATABASE your_db TO db_monitor;
GRANT pg_monitor TO db_monitor;
```
## How It Works
```
┌─────────────────────────────────┐
│ DB Monitor │
│ │
│ Collector ──→ SQLite (metrics) │
│ │ │ │
│ │ Alert Engine │
│ │ (Telegram) │
│ ↓ ↓ │
│ REST API + Web Dashboard │
│ :9432 │
└────────────┬────────────────────┘
│
┌──────────┼──────────┐
↓ ↓ ↓
PostgreSQL PostgreSQL PostgreSQL
```
Every N seconds (default: 15), the collector queries `pg_stat_activity`, `pg_stat_database`, `pg_locks`, and friends. Metrics get stored in an embedded SQLite database. The dashboard reads from SQLite and shows live charts via Chart.js.
## Built With
Go · SQLite · Chart.js · Docker
## License
MIT