|
| 1 | +# Cardano DB Sync - Monitoring |
| 2 | + |
| 3 | +Local development monitoring using Prometheus and Grafana for PostgreSQL and system metrics. |
| 4 | + |
| 5 | +## Quick Setup |
| 6 | + |
| 7 | +### 1. Install Tools |
| 8 | + |
| 9 | +```bash |
| 10 | +# macOS |
| 11 | +brew install prometheus postgres_exporter node_exporter grafana |
| 12 | + |
| 13 | +# Linux (apt) |
| 14 | +sudo apt-get install prometheus postgres-exporter prometheus-node-exporter grafana |
| 15 | + |
| 16 | +# Linux (yum) |
| 17 | +sudo yum install prometheus postgres_exporter node_exporter grafana |
| 18 | +``` |
| 19 | + |
| 20 | +### 2. Setup PostgreSQL Monitoring User |
| 21 | + |
| 22 | +```sql |
| 23 | +-- Connect to your database |
| 24 | +psql -U postgres -d cexplorer |
| 25 | + |
| 26 | +-- Create monitoring user |
| 27 | +CREATE USER postgres_exporter WITH PASSWORD 'secure_password'; |
| 28 | +GRANT pg_monitor TO postgres_exporter; |
| 29 | +GRANT CONNECT ON DATABASE cexplorer TO postgres_exporter; |
| 30 | +``` |
| 31 | + |
| 32 | +### 3. Start Monitoring |
| 33 | + |
| 34 | +```bash |
| 35 | +cd dev-tools/monitoring |
| 36 | +./scripts/start-monitoring.sh |
| 37 | +``` |
| 38 | + |
| 39 | +This launches a tmux session with Prometheus and exporters. |
| 40 | + |
| 41 | +### 4. Start Grafana |
| 42 | + |
| 43 | +```bash |
| 44 | +# macOS |
| 45 | +brew services start grafana |
| 46 | + |
| 47 | +# Linux |
| 48 | +sudo systemctl start grafana-server |
| 49 | +``` |
| 50 | + |
| 51 | +## Access Dashboards |
| 52 | + |
| 53 | +- **Prometheus**: http://localhost:9090 |
| 54 | +- **Grafana**: http://localhost:3000 (default: admin/admin) |
| 55 | + |
| 56 | +## Grafana Setup |
| 57 | + |
| 58 | +1. Open http://localhost:3000 |
| 59 | +2. Add Prometheus data source: |
| 60 | + - Configuration → Data Sources → Add data source |
| 61 | + - Select Prometheus |
| 62 | + - URL: `http://localhost:9090` |
| 63 | + - Save & Test |
| 64 | +3. Import dashboard: |
| 65 | + - Dashboards → Import |
| 66 | + - Upload `config/grafana-db-sync.json` |
| 67 | + - Select Prometheus data source |
| 68 | + |
| 69 | +## Key Metrics |
| 70 | + |
| 71 | +- **System**: CPU, memory usage (node_exporter) |
| 72 | +- **PostgreSQL**: Connections, transaction rates, cache hit ratio |
| 73 | +- **Sync Progress**: Block height, epoch duration |
| 74 | + |
| 75 | +## Troubleshooting |
| 76 | + |
| 77 | +**postgres_exporter fails to connect**: |
| 78 | +- Verify monitoring user exists and has permissions |
| 79 | +- Set `DATA_SOURCE_NAME` with correct credentials in `scripts/start-monitoring.sh` |
| 80 | + |
| 81 | +**Prometheus shows "DOWN" targets**: |
| 82 | +- Check exporters are running: `ps aux | grep exporter` |
| 83 | +- Test endpoints: `curl http://localhost:9187/metrics` and `curl http://localhost:9100/metrics` |
| 84 | + |
| 85 | +**Port already in use**: |
| 86 | +```bash |
| 87 | +# Kill processes using ports |
| 88 | +lsof -ti:9090 | xargs kill # Prometheus |
| 89 | +lsof -ti:9100 | xargs kill # node_exporter |
| 90 | +lsof -ti:9187 | xargs kill # postgres_exporter |
| 91 | +``` |
| 92 | + |
| 93 | +## Stop Services |
| 94 | + |
| 95 | +```bash |
| 96 | +# Stop monitoring |
| 97 | +tmux kill-session -t cardano-monitoring |
| 98 | + |
| 99 | +# Stop Grafana |
| 100 | +brew services stop grafana # macOS |
| 101 | +sudo systemctl stop grafana-server # Linux |
| 102 | +``` |
| 103 | + |
| 104 | +## Files |
| 105 | + |
| 106 | +- `scripts/start-monitoring.sh` - Launch monitoring suite |
| 107 | +- `config/prometheus.yml` - Prometheus configuration |
| 108 | +- `config/grafana-db-sync.json` - Grafana dashboard |
| 109 | +- `docs/METRICS.md` - Complete metrics reference |
| 110 | + |
| 111 | +## See Also |
| 112 | + |
| 113 | +- [Prometheus Documentation](https://prometheus.io/docs/) |
| 114 | +- [Grafana Documentation](https://grafana.com/docs/) |
0 commit comments