#!/bin/bash # Gravl Monitoring Check - Phase 10-09 Pre-Launch # Runs periodic health checks on staging and readiness for production components. TIMESTAMP=$(date -Iseconds) REPORT_FILE="/workspace/gravl/monitoring/health_report.json" echo "Running Gravl Health Check: $TIMESTAMP" # 1. Check Staging API Health (Example endpoint) STAGING_API_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://api.staging.gravl.example.com/health || echo "FAIL") # 2. Check Cert-Manager Pods CERT_MANAGER_STATUS=$(kubectl get pods -n cert-manager --no-headers | awk '{print $3}' | grep -v Running | wc -l) if [ "$CERT_MANAGER_STATUS" -eq 0 ]; then CERT_STATUS="HEALTHY"; else CERT_STATUS="UNHEALTHY"; fi # 3. Check Sealed Secrets Pods SEALED_SECRETS_STATUS=$(kubectl get pods -n kube-system -l app.kubernetes.io/name=sealed-secrets --no-headers | awk '{print $3}' | grep -v Running | wc -l) if [ "$SEALED_SECRETS_STATUS" -eq 0 ]; then SEALED_STATUS="HEALTHY"; else SEALED_STATUS="UNHEALTHY"; fi # 4. Check Staging Latency LATENCY=$(curl -s -o /dev/null -w "%{time_total}" https://api.staging.gravl.example.com/health || echo "0") # Generate JSON Report cat < "$REPORT_FILE" { "timestamp": "$TIMESTAMP", "staging_api_http_code": "$STAGING_API_STATUS", "cert_manager": "$CERT_STATUS", "sealed_secrets": "$SEALED_STATUS", "latency_ms": $(echo "$LATENCY * 1000" | bc -l 2>/dev/null || echo 0), "summary": "Staging environment is $([ "$STAGING_API_STATUS" == "200" ] && echo "ONLINE" || echo "OFFLINE"). Infrastructure components: Cert-Manager ($CERT_STATUS), Sealed-Secrets ($SEALED_STATUS)." } EOF echo "Health report generated at $REPORT_FILE"