pgSentinel is a comprehensive, enterprise-grade monitoring and management platform for pgbalancer - the PostgreSQL connection pooler. Built with modern technologies, it provides real-time metrics, interactive dashboards, and intelligent alerting for your PostgreSQL infrastructure.
- β‘ Real-time Monitoring - WebSocket-based live updates with sub-second latency
- π Beautiful Dashboards - Interactive visualizations built with React and Recharts
- π Smart Alerting - Prometheus-based alerts with configurable thresholds
- π Historical Analysis - Long-term metrics storage and trend analysis
- π― Node Management - Attach/detach backend nodes with one click
- π Secure & Scalable - Production-ready architecture with Docker support
- π¨ Modern UI/UX - Responsive design with Tailwind CSS
- π§ Configuration Management - Edit and reload pgbalancer config via UI
- Architecture
- Technology Stack
- Quick Start
- Installation
- Configuration
- Usage
- API Documentation
- Monitoring & Alerts
- Development
- Deployment
- Contributing
- License
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β pgSentinel Platform β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β β β βββββββββββββββ ββββββββββββββββ βββββββββββββββββ β β β Frontend β β Backend β β Prometheus β β β β (Next.js) ββββββ (FastAPI) ββββββ (Metrics) β β β βββββββββββββββ ββββββββββββββββ βββββββββββββββββ β β β β β β β β β β β β βΌ βΌ βΌ β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β β Real-time WebSocket Connection β β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β β β ββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ β βΌ ββββββββββββββββββββββββββββββββββββ β pgbalancer Cluster β ββββββββββββββββββββββββββββββββββββ€ β ββββββββ ββββββββ ββββββββ β β β Node β β Node β β Node β β β β 1 β β 2 β β 3 β β β ββββββββ ββββββββ ββββββββ β ββββββββββββββββββββββββββββββββββββ | Component | Technology | Purpose |
|---|---|---|
| Frontend | Next.js 14, React 18, TypeScript | Interactive web dashboard |
| Backend API | FastAPI, Python 3.12, WebSocket | RESTful API & real-time updates |
| Metrics | Prometheus, Node Exporter | Metrics collection & storage |
| Visualization | Grafana, Recharts | Data visualization & dashboards |
| Database | PostgreSQL 17 | Metadata & configuration storage |
| Cache | Redis 7 | Session management & caching |
| Monitoring | Alertmanager | Alert routing & notification |
- Framework: Next.js 14 (React 18)
- Language: TypeScript
- Styling: Tailwind CSS 3
- Charts: Recharts 2
- State Management: React Hooks
- HTTP Client: Axios
- WebSocket: socket.io-client
- Icons: Lucide React
- Framework: FastAPI 0.115
- Language: Python 3.12
- Async Runtime: uvicorn, asyncio
- Database ORM: SQLAlchemy 2
- WebSocket: Native WebSocket support
- Metrics: Prometheus Client
- Validation: Pydantic 2
- Metrics: Prometheus 2.x
- Visualization: Grafana 10.x
- Alerts: Alertmanager 0.26
- System Metrics: Node Exporter
- Containerization: Docker 24+
- Orchestration: Docker Compose 3.9
- Database: PostgreSQL 17
- Cache: Redis 7
- Docker 24+ and Docker Compose
- Git
- 4GB+ RAM
- 10GB+ disk space
# Clone the repository git clone https://github.com/your-org/pgsentinel.git cd pgSentinel # Start all services docker-compose up -d # View logs docker-compose logs -f # Access the dashboard open http://localhost:3000| Service | URL | Credentials |
|---|---|---|
| pgSentinel Dashboard | http://localhost:3000 | - |
| Backend API | http://localhost:8000 | - |
| API Documentation | http://localhost:8000/docs | - |
| Prometheus | http://localhost:9090 | - |
| Grafana | http://localhost:3001 | admin / admin |
| Alertmanager | http://localhost:9093 | - |
# Production deployment docker-compose -f docker-compose.yml up -d # Development with hot reload docker-compose -f docker-compose.dev.yml upcd backend # Create virtual environment python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install dependencies pip install -r requirements.txt # Set environment variables export DATABASE_URL="postgresql://user:pass@localhost:5432/pgsentinel" export REDIS_URL="redis://localhost:6379/0" # Run backend uvicorn main:app --reload --host 0.0.0.0 --port 8000cd frontend # Install dependencies npm install # Set environment variables echo "NEXT_PUBLIC_API_URL=http://localhost:8000" > .env.local echo "NEXT_PUBLIC_WS_URL=ws://localhost:8000/ws/live" >> .env.local # Run development server npm run dev # Or build for production npm run build npm start# Database DATABASE_URL=postgresql://user:pass@localhost:5432/pgsentinel # Redis REDIS_URL=redis://localhost:6379/0 # pgbalancer PGBALANCER_CONFIG=/path/to/pgbalancer.conf # Logging LOG_LEVEL=INFO # Security SECRET_KEY=your-secret-key-here ALLOWED_HOSTS=*NEXT_PUBLIC_API_URL=http://localhost:8000 NEXT_PUBLIC_WS_URL=ws://localhost:8000/ws/live NEXT_TELEMETRY_DISABLED=1Update pgbalancer.conf to enable metrics export:
# Enable metrics endpoint enable_metrics = on metrics_port = 9187 # Connection pool settings num_init_children = 32 max_pool = 4The main dashboard provides:
-
System Metrics
- CPU usage
- Memory utilization
- Network I/O
- Disk I/O
-
Connection Pool Stats
- Total connections
- Active connections
- Idle connections
- Pool utilization %
-
Backend Nodes
- Node status (up/down)
- Connection count per node
- Replication lag
- Primary/Replica roles
-
Real-time Charts
- System resource trends
- Connection trends
- Query performance
- Replication lag graphs
# Via UI: Click "Detach" button on node card # Via API: curl -X POST http://localhost:8000/api/v1/backends/1/detach# Via UI: Click "Attach" button on node card # Via API: curl -X POST http://localhost:8000/api/v1/backends/1/attach# Get current configuration curl http://localhost:8000/api/v1/config # Update configuration curl -X PUT http://localhost:8000/api/v1/config \ -H "Content-Type: application/json" \ -d '{"num_init_children": 64}' # Reload configuration curl -X POST http://localhost:8000/api/v1/reload| Alert | Threshold | Severity | Description |
|---|---|---|---|
| HighPoolUtilization | >80% | Warning | Pool is heavily utilized |
| PoolExhausted | Waiting clients > 0 | Critical | No available connections |
| BackendNodeDown | Status = 0 | Critical | Backend node is unreachable |
| HighReplicationLag | >10MB | Warning | Replica is lagging |
| CriticalReplicationLag | >100MB | Critical | Severe replication delay |
| HighCPUUsage | >80% | Warning | System CPU is high |
| HighMemoryUsage | >85% | Warning | System memory is high |
Import pre-built Grafana dashboards:
# Import dashboard curl -X POST http://localhost:3001/api/dashboards/import \ -u admin:admin \ -H "Content-Type: application/json" \ -d @monitoring/grafana/dashboards/pgbalancer-overview.jsonpgSentinel/ βββ backend/ # FastAPI backend β βββ main.py # Main application β βββ requirements.txt # Python dependencies β βββ Dockerfile # Backend container βββ frontend/ # Next.js frontend β βββ app/ # Next.js 14 app directory β βββ components/ # React components β β βββ common/ # Reusable components β β βββ dashboard/ # Dashboard-specific β β βββ charts/ # Chart components β β βββ nodes/ # Node management β βββ hooks/ # Custom React hooks β βββ services/ # API service layer β βββ types/ # TypeScript types β βββ utils/ # Utility functions β βββ Dockerfile # Frontend container βββ monitoring/ # Monitoring stack β βββ prometheus/ # Prometheus config β β βββ prometheus.yml # Main config β β βββ rules/ # Alert rules β βββ grafana/ # Grafana dashboards β βββ alertmanager/ # Alert routing βββ docker/ # Docker configs βββ docs/ # Documentation βββ docker-compose.yml # Orchestration # Backend tests cd backend pytest # Frontend tests cd frontend npm test # E2E tests npm run test:e2e# Backend linting cd backend ruff check . black --check . # Frontend linting cd frontend npm run lint npm run type-check# Build and deploy docker-compose -f docker-compose.prod.yml up -d # Scale services docker-compose up -d --scale backend=4 # Update services docker-compose pull docker-compose up -d# Apply Kubernetes manifests kubectl apply -f k8s/ # Check status kubectl get pods -n pgsentinelWe welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- pgbalancer team for the excellent connection pooler
- PostgreSQL community
- FastAPI and Next.js teams
- All contributors and users
- Documentation: docs.pgsentinel.io
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@pgsentinel.io
Built with β€οΈ by pgElephant, Inc.
Website β’ Documentation β’ Blog
