الملفات
ghaymah-exam-sre-abdelrahman/health-check.sh

26 أسطر
1.0 KiB
Bash
ملف تنفيذي

#!/bin/bash
# استبدل هذا الرابط بالرابط العام المستلم من غيمة
TARGET_URL="https://q1-app.deploy.ghaymah.systems/health"
echo "Starting Monitoring for $TARGET_URL..."
while true; do
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# جلب الاستجابة وحساب الوقت
RESPONSE=$(curl -s "$TARGET_URL")
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$TARGET_URL")
RESPONSE_TIME=$(curl -s -w "%{time_total}" -o /dev/null "$TARGET_URL")
# استخراج عدد الطلبات من الـ Endpoint
TOTAL_REQUESTS=$(echo "$RESPONSE" | grep -o '"total_requests":[0-9]*' | grep -o '[0-9]*')
echo "[$TIMESTAMP] Status: $HTTP_STATUS | Latency: ${RESPONSE_TIME}s | Requests: ${TOTAL_REQUESTS:-0}"
# تحديث ملف المتركس للداشبورد
echo "{\"timestamp\": \"$TIMESTAMP\", \"status\": \"$HTTP_STATUS\", \"latency\": $RESPONSE_TIME, \"total_requests\": ${TOTAL_REQUESTS:-0}}" > metrics.json
sleep 30
done