Added comprehensive production infrastructure: Systemd Service: - guruconnect.service with auto-restart, resource limits, security hardening - setup-systemd.sh installation script Prometheus Metrics: - Added prometheus-client dependency - Created metrics module tracking: - HTTP requests (count, latency) - Sessions (created, closed, active) - Connections (WebSocket, by type) - Errors (by type) - Database operations (count, latency) - Server uptime - Added /metrics endpoint - Background task for uptime updates Monitoring Configuration: - prometheus.yml with scrape configs for GuruConnect and node_exporter - alerts.yml with alerting rules - grafana-dashboard.json with 10 panels - setup-monitoring.sh installation script PostgreSQL Backups: - backup-postgres.sh with gzip compression - restore-postgres.sh with safety checks - guruconnect-backup.service and .timer for automated daily backups - Retention policy: 30 daily, 4 weekly, 6 monthly Health Monitoring: - health-monitor.sh checking HTTP, disk, memory, database, metrics - guruconnect.logrotate for log rotation - Email alerts on failures Updated CHECKLIST_STATE.json to reflect Week 1 completion (77%) and Week 2 start. Created PHASE1_WEEK2_INFRASTRUCTURE.md with comprehensive planning. Ready for deployment and testing on RMM server.
103 lines
2.7 KiB
Bash
103 lines
2.7 KiB
Bash
#!/bin/bash
|
|
# GuruConnect Monitoring Setup Script
|
|
# Installs and configures Prometheus and Grafana
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
echo "========================================="
|
|
echo "GuruConnect Monitoring Setup"
|
|
echo "========================================="
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo -e "${RED}ERROR: This script must be run as root (sudo)${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Update package list
|
|
echo "Updating package list..."
|
|
apt-get update
|
|
|
|
# Install Prometheus
|
|
echo ""
|
|
echo "Installing Prometheus..."
|
|
apt-get install -y prometheus prometheus-node-exporter
|
|
|
|
# Copy Prometheus configuration
|
|
echo "Copying Prometheus configuration..."
|
|
cp prometheus.yml /etc/prometheus/prometheus.yml
|
|
if [ -f "alerts.yml" ]; then
|
|
cp alerts.yml /etc/prometheus/alerts.yml
|
|
fi
|
|
|
|
# Set permissions
|
|
chown prometheus:prometheus /etc/prometheus/prometheus.yml
|
|
if [ -f "/etc/prometheus/alerts.yml" ]; then
|
|
chown prometheus:prometheus /etc/prometheus/alerts.yml
|
|
fi
|
|
|
|
# Restart Prometheus
|
|
echo "Restarting Prometheus..."
|
|
systemctl restart prometheus
|
|
systemctl enable prometheus
|
|
systemctl restart prometheus-node-exporter
|
|
systemctl enable prometheus-node-exporter
|
|
|
|
# Install Grafana
|
|
echo ""
|
|
echo "Installing Grafana..."
|
|
apt-get install -y software-properties-common
|
|
add-apt-repository -y "deb https://packages.grafana.com/oss/deb stable main"
|
|
wget -q -O - https://packages.grafana.com/gpg.key | apt-key add -
|
|
apt-get update
|
|
apt-get install -y grafana
|
|
|
|
# Start Grafana
|
|
echo "Starting Grafana..."
|
|
systemctl start grafana-server
|
|
systemctl enable grafana-server
|
|
|
|
# Wait for Grafana to start
|
|
sleep 5
|
|
|
|
# Configure Grafana data source (Prometheus)
|
|
echo ""
|
|
echo "Configuring Grafana data source..."
|
|
curl -X POST -H "Content-Type: application/json" \
|
|
-d '{
|
|
"name":"Prometheus",
|
|
"type":"prometheus",
|
|
"url":"http://localhost:9090",
|
|
"access":"proxy",
|
|
"isDefault":true
|
|
}' \
|
|
http://admin:admin@localhost:3000/api/datasources || true
|
|
|
|
echo ""
|
|
echo "========================================="
|
|
echo "Monitoring Setup Complete!"
|
|
echo "========================================="
|
|
echo ""
|
|
echo "Services:"
|
|
echo " Prometheus: http://172.16.3.30:9090"
|
|
echo " Grafana: http://172.16.3.30:3000 (default login: admin/admin)"
|
|
echo " Node Exporter: http://172.16.3.30:9100/metrics"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Access Grafana at http://172.16.3.30:3000"
|
|
echo "2. Login with default credentials (admin/admin)"
|
|
echo "3. Change the default password"
|
|
echo "4. Import the dashboard from grafana-dashboard.json"
|
|
echo "5. Configure alerting (optional)"
|
|
echo ""
|
|
echo "To import the dashboard:"
|
|
echo " Grafana > Dashboards > Import > Upload JSON file"
|
|
echo " Select: infrastructure/grafana-dashboard.json"
|
|
echo ""
|