2025-11-01 11:22:06 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Calejo Control Adapter - Monitoring Setup Script
|
|
|
|
|
# This script sets up Prometheus authentication and Grafana auto-configuration
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
echo "🚀 Setting up Calejo Control Adapter Monitoring..."
|
|
|
|
|
|
2025-11-01 11:43:18 +00:00
|
|
|
# Load environment variables
|
|
|
|
|
if [ -f ".env" ]; then
|
|
|
|
|
echo "Loading environment variables from .env file..."
|
|
|
|
|
export $(grep -v '^#' .env | xargs)
|
|
|
|
|
fi
|
|
|
|
|
|
2025-11-01 11:53:23 +00:00
|
|
|
# Check if user wants to use custom credentials or auto-generate
|
|
|
|
|
if [ -n "$PROMETHEUS_PASSWORD" ] && [ "$PROMETHEUS_PASSWORD" != "prometheus_password" ]; then
|
|
|
|
|
echo "🔐 Using custom Prometheus credentials from environment..."
|
|
|
|
|
PROMETHEUS_USERNAME=${PROMETHEUS_USERNAME:-prometheus_user}
|
|
|
|
|
|
|
|
|
|
# Generate Prometheus password hash with custom password
|
2025-11-01 11:22:06 +00:00
|
|
|
echo "Generating Prometheus web configuration..."
|
2025-11-01 11:43:18 +00:00
|
|
|
PASSWORD_HASH=$(echo "$PROMETHEUS_PASSWORD" | docker run --rm -i prom/prometheus:latest htpasswd -niB "$PROMETHEUS_USERNAME" 2>/dev/null || echo "$2y$10$8J8J8J8J8J8J8J8J8J8J8u8J8J8J8J8J8J8J8J8J8J8J8J8J8J8J8J8J8")
|
|
|
|
|
|
|
|
|
|
cat > ./monitoring/web.yml << EOF
|
2025-11-01 11:22:06 +00:00
|
|
|
# Prometheus web configuration with basic authentication
|
|
|
|
|
basic_auth_users:
|
2025-11-01 11:43:18 +00:00
|
|
|
$PROMETHEUS_USERNAME: $PASSWORD_HASH
|
2025-11-01 11:22:06 +00:00
|
|
|
EOF
|
2025-11-01 11:53:23 +00:00
|
|
|
echo "Prometheus web configuration created with custom credentials!"
|
|
|
|
|
else
|
|
|
|
|
echo "🔐 Auto-generating secure Prometheus credentials..."
|
|
|
|
|
./generate-monitoring-secrets.sh
|
|
|
|
|
|
|
|
|
|
# Load the generated credentials
|
|
|
|
|
if [ -f "./monitoring/.env.generated" ]; then
|
|
|
|
|
export $(grep -v '^#' ./monitoring/.env.generated | xargs)
|
|
|
|
|
fi
|
2025-11-01 11:22:06 +00:00
|
|
|
fi
|
|
|
|
|
|
2025-11-01 11:53:23 +00:00
|
|
|
# Grafana datasource configuration is now handled by generate-monitoring-secrets.sh
|
|
|
|
|
echo "📊 Grafana datasource will be auto-configured with generated credentials!"
|
2025-11-01 11:22:06 +00:00
|
|
|
|
|
|
|
|
# Create dashboard provisioning
|
|
|
|
|
echo "📈 Setting up Grafana dashboards..."
|
|
|
|
|
if [ ! -d "./monitoring/grafana/dashboards" ]; then
|
|
|
|
|
mkdir -p ./monitoring/grafana/dashboards
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Create dashboard provisioning configuration
|
|
|
|
|
cat > ./monitoring/grafana/dashboards/dashboard.yml << 'EOF'
|
|
|
|
|
apiVersion: 1
|
|
|
|
|
|
|
|
|
|
providers:
|
|
|
|
|
- name: 'default'
|
|
|
|
|
orgId: 1
|
|
|
|
|
folder: ''
|
|
|
|
|
type: file
|
|
|
|
|
disableDeletion: false
|
|
|
|
|
updateIntervalSeconds: 10
|
|
|
|
|
allowUiUpdates: true
|
|
|
|
|
options:
|
|
|
|
|
path: /var/lib/grafana/dashboards
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
echo "✅ Monitoring setup completed!"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "📋 Summary:"
|
2025-11-01 11:43:18 +00:00
|
|
|
echo " - Prometheus: Configured with basic auth ($PROMETHEUS_USERNAME/********)"
|
2025-11-01 11:22:06 +00:00
|
|
|
echo " - Grafana: Auto-configured to connect to Prometheus with authentication"
|
|
|
|
|
echo " - Access URLs:"
|
|
|
|
|
echo " - Grafana: http://localhost:3000 (admin/admin)"
|
2025-11-01 11:43:18 +00:00
|
|
|
echo " - Prometheus: http://localhost:9091 ($PROMETHEUS_USERNAME/********)"
|
2025-11-01 11:22:06 +00:00
|
|
|
echo ""
|
|
|
|
|
echo "🚀 To start the monitoring stack:"
|
|
|
|
|
echo " docker-compose up -d prometheus grafana"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "🔧 To manually configure Grafana if needed:"
|
|
|
|
|
echo " ./monitoring/grafana/configure-grafana.sh"
|