A comprehensive PostgreSQL monitoring solution with multi-database support, multi-channel alerting, automated actions, and flexible deployment options.
# Clone and build
git clone https://github.com/warkanum/go-postgres-stat-alert.git
cd postgres-stat-alert
make build
# Configure
cp config.yaml.sample config.yaml
nano config.yaml # Edit databases and alert settings
# Local development
./postgres-stat-alert config.yaml
# Or with Docker
make docker-up
# Or install as systemd service (CentOS/RHEL)
sudo ./install-centos.sh
databases:
- instance: "production-db-01"
host: "localhost"
port: 5432
username: "monitor_user"
password: "secure_password"
database: "production"
sslmode: "verify-full"
- instance: "staging-db-02"
host: "staging.example.com"
port: 5432
username: "monitor_user"
database: "staging"
sslmode: "require"
alerts:
email:
enabled: true
smtp_host: "smtp.gmail.com"
smtp_port: 587
username: "alerts@company.com"
password: "app_password"
tls: true
interval: "3m"
telegram:
enabled: true
bot_token: "123456:your_bot_token"
chat_id: "your_chat_id"
interval: "1m"
queries:
- name: "connection_count"
sql: "SELECT count(*) FROM pg_stat_activity WHERE state = 'active'"
interval: "30s"
alert_rules:
- condition: "gt"
value: 100
message: "High connection count detected"
category: "performance"
to: "dba@company.com"
channels: ["email", "telegram"]
execute_action: "/scripts/restart_pgbouncer.sh"
| Channel | Features | Use Case |
|---|---|---|
| HTML templates, professional formatting | Management reports, audit trails | |
| Telegram | Instant notifications, group chats | Development teams, immediate alerts |
| Discord | Rich embeds, color coding | Team collaboration, status updates |
| Teams | Professional cards, structured data | Business communications |
| Webhook | Custom integrations, JSON payload | External systems, custom workflows |
# One-command installation
make build-linux
sudo ./install-centos.sh
# Service management
sudo systemctl start postgres-stat-alert
sudo systemctl enable postgres-stat-alert
sudo journalctl -u postgres-stat-alert -f
# Using Docker Compose
make docker-up
make docker-logs
# Or standalone Docker
docker run -d \
--name postgres-stat-alert \
-v $(pwd)/config.yaml:/etc/postgres-stat-alert/config.yaml:ro \
-v $(pwd)/logs:/var/log/postgres-stat-alert \
postgres-stat-alert:latest
# Apply manifests
kubectl apply -f k8s/
kubectl logs -f deployment/postgres-stat-alert -n monitoring
databases:
- instance: "prod-primary"
host: "prod-db-01.internal"
database: "app_production"
- instance: "prod-replica"
host: "prod-db-02.internal"
database: "app_production"
- instance: "staging"
host: "staging-db.internal"
database: "app_staging"
# Production: Email + Teams (management)
channels: ["email", "teams"]
# Staging: Discord + Telegram (development)
channels: ["discord", "telegram"]
execute_action: "/scripts/restart_connection_pooler.sh" # Auto-restart on high load
execute_action: "/scripts/kill_slow_queries.py --timeout 300" # Terminate slow queries
execute_action: "/scripts/cleanup_temp_files.sh" # Clean up storage issues
# Warning level
- condition: "gt"
value: 80
channels: ["discord"]
# Critical level
- condition: "gt"
value: 95
channels: ["email", "telegram", "teams"]
execute_action: "/emergency/scale_up.sh"
# Install dependencies
make deps
# Build for current platform
make build
# Build for Linux (deployment)
make build-linux
# Run tests
make test
# Development mode (auto-rebuild)
make dev
make fmtmake lint# Check service status
make status
# View logs
make logs
tail -f /var/log/postgres-stat-alert/*.log
# Validate configuration
make validate-config
# Test database connections
psql "host=localhost port=5432 dbname=mydb user=monitor_user"
# Check monitoring queries per instance
SELECT count(*) FROM pg_stat_activity WHERE state = 'active';
# Test Telegram bot
curl -X POST "https://api.telegram.org/bot$TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id":"$CHAT_ID","text":"Test"}'
# Check email configuration
telnet smtp.gmail.com 587
MIT License - see LICENSE file for details.