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
|
|
|
|
|
|
|
|
|
|
# Set default values if not provided
|
|
|
|
|
PROMETHEUS_USERNAME=${PROMETHEUS_USERNAME:-prometheus_user}
|
|
|
|
|
PROMETHEUS_PASSWORD=${PROMETHEUS_PASSWORD:-prometheus_password}
|
|
|
|
|
|
2025-11-01 11:22:06 +00:00
|
|
|
# Generate Prometheus password hash if needed
|
|
|
|
|
echo "🔐 Setting up Prometheus authentication..."
|
|
|
|
|
if [ ! -f "./monitoring/web.yml" ]; then
|
|
|
|
|
echo "Generating Prometheus web configuration..."
|
2025-11-01 11:43:18 +00:00
|
|
|
# Generate password hash using htpasswd
|
|
|
|
|
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
|
|
|
|
|
echo "Prometheus web configuration created!"
|
2025-11-01 11:43:18 +00:00
|
|
|
echo "⚠️ Note: web.yml contains password hash and should not be committed to git"
|
2025-11-01 11:22:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Update Grafana datasource configuration
|
|
|
|
|
echo "📊 Configuring Grafana datasource..."
|
|
|
|
|
cat > ./monitoring/grafana/datasources/prometheus.yml << 'EOF'
|
|
|
|
|
apiVersion: 1
|
|
|
|
|
|
|
|
|
|
datasources:
|
|
|
|
|
- name: Prometheus
|
|
|
|
|
type: prometheus
|
|
|
|
|
access: proxy
|
|
|
|
|
url: http://prometheus:9090
|
|
|
|
|
isDefault: true
|
|
|
|
|
editable: true
|
|
|
|
|
# Basic authentication configuration
|
|
|
|
|
basicAuth: true
|
|
|
|
|
basicAuthUser: prometheus_user
|
|
|
|
|
basicAuthPassword: prometheus_password
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
echo "Grafana datasource configuration updated!"
|
|
|
|
|
|
|
|
|
|
# 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"
|