feat: complete SRE exam deliverables for Ghaymah & Qabilah platform submission
هذا الالتزام موجود في:
41
q1-deploy-monitor/health-check.sh
Normal file
41
q1-deploy-monitor/health-check.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Ghaymah Cloud SRE — Q1 Automated Health Check Monitoring Script (Bash)
|
||||
# Performs HTTP /healthz checks every 30 seconds, logs latency & alerts
|
||||
# ==============================================================================
|
||||
|
||||
TARGET_URL="${MONITOR_TARGET_URL:-http://localhost:8000/healthz}"
|
||||
CHECK_INTERVAL=30
|
||||
LOG_FILE="./health_monitor.log"
|
||||
|
||||
echo "⚡ Starting Ghaymah SRE Health Check Script"
|
||||
echo "🎯 Target URL: $TARGET_URL"
|
||||
echo "⏱️ Check Interval: ${CHECK_INTERVAL}s"
|
||||
echo "--------------------------------------------------------"
|
||||
|
||||
while true; do
|
||||
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
# Execute cURL measuring total time in seconds & status code
|
||||
START_TIME=$(date +%s%N)
|
||||
HTTP_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 "$TARGET_URL")
|
||||
END_TIME=$(date +%s%N)
|
||||
|
||||
# Calculate round trip time in milliseconds
|
||||
LATENCY_MS=$(( (END_TIME - START_TIME) / 1000000 ))
|
||||
|
||||
if [ "$HTTP_RESPONSE" -eq 200 ]; then
|
||||
STATUS_STR="[SUCCESS] 🟢 Status: HTTP 200 OK | Latency: ${LATENCY_MS}ms"
|
||||
echo "[$TIMESTAMP] $STATUS_STR"
|
||||
echo "[$TIMESTAMP] SUCCESS status=200 latency=${LATENCY_MS}ms" >> "$LOG_FILE"
|
||||
else
|
||||
STATUS_STR="[ALERT] 🚨 CRITICAL: Service Unhealthy! Code: ${HTTP_RESPONSE} | Latency: ${LATENCY_MS}ms"
|
||||
echo "[$TIMESTAMP] $STATUS_STR"
|
||||
echo "[$TIMESTAMP] ALERT status=${HTTP_RESPONSE} latency=${LATENCY_MS}ms" >> "$LOG_FILE"
|
||||
|
||||
# Simulated PagerDuty / Ghaymah Alert trigger
|
||||
echo "🚨 [PAGERDUTY ALERT] Service at $TARGET_URL responded with HTTP $HTTP_RESPONSE at $TIMESTAMP"
|
||||
fi
|
||||
|
||||
sleep $CHECK_INTERVAL
|
||||
done
|
||||
المرجع في مشكلة جديدة
حظر مستخدم