commit d0e5f30eacef650123328f1777f047d622489191 Author: Abdelrahman-17 Date: Sun Jul 26 14:50:01 2026 +0300 Initial commit for Ghaymah SRE Exam diff --git a/q1-deploy-monitor/Dockerfile b/q1-deploy-monitor/Dockerfile new file mode 100644 index 0000000..4705e4f --- /dev/null +++ b/q1-deploy-monitor/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.10-slim + +WORKDIR /app + +RUN pip install --no-cache-dir fastapi uvicorn requests + +COPY . . + +EXPOSE 8000 + +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"] diff --git a/q1-deploy-monitor/app.py b/q1-deploy-monitor/app.py new file mode 100644 index 0000000..60c3832 --- /dev/null +++ b/q1-deploy-monitor/app.py @@ -0,0 +1,24 @@ +from fastapi import FastAPI +import time + +app = FastAPI() +start_time = time.time() +request_count = 0 + +@app.middleware("http") +def count_requests(request, call_next): + global request_count + request_count += 1 + return call_next(request) + +@app.get("/") +def root(): + return {"message": "Welcome to Ghaymah SRE Service"} + +@app.get("/health") +def health(): + return { + "status": "healthy", + "uptime_seconds": round(time.time() - start_time, 2), + "total_requests": request_count + } diff --git a/q1-deploy-monitor/dashboard.html b/q1-deploy-monitor/dashboard.html new file mode 100644 index 0000000..22a7a78 --- /dev/null +++ b/q1-deploy-monitor/dashboard.html @@ -0,0 +1,48 @@ + + + + + Ghaymah App Dashboard + + + +

🚀 لوحة مراقبة التطبيق - Ghaymah Cloud

+
+
+

الحالة (Status)

+

--

+
+
+

زمن الاستجابة (Latency)

+

0 ثانية

+
+
+

إجمالي الطلبات (Total Requests)

+

0

+
+
+ + + + diff --git a/q1-deploy-monitor/health-check.sh b/q1-deploy-monitor/health-check.sh new file mode 100755 index 0000000..a04a30a --- /dev/null +++ b/q1-deploy-monitor/health-check.sh @@ -0,0 +1,25 @@ +#!/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 diff --git a/q1-deploy-monitor/metrics.json b/q1-deploy-monitor/metrics.json new file mode 100644 index 0000000..f7488ac --- /dev/null +++ b/q1-deploy-monitor/metrics.json @@ -0,0 +1 @@ +{"timestamp": "2026-07-26T11:28:46Z", "status": "200", "latency": 0.004614}