From 10106651a4fe72c82476d0083247b24c59c6f940 Mon Sep 17 00:00:00 2001 From: Abdelrahman-17 Date: Sun, 26 Jul 2026 15:37:55 +0300 Subject: [PATCH] Serve live Dashboard directly from FastAPI on /dashboard --- app.py | 66 +++++++++++++++++++++++++++++++++++----- q1-deploy-monitor/app.py | 66 +++++++++++++++++++++++++++++++++++----- 2 files changed, 116 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index 60c3832..94852b6 100644 --- a/app.py +++ b/app.py @@ -1,24 +1,74 @@ from fastapi import FastAPI +from fastapi.responses import HTMLResponse import time app = FastAPI() + start_time = time.time() request_count = 0 -@app.middleware("http") -def count_requests(request, call_next): +@app.get("/") +def read_root(): 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(): +def health_check(): + global request_count + request_count += 1 return { - "status": "healthy", + "status": "ok", "uptime_seconds": round(time.time() - start_time, 2), "total_requests": request_count } + +@app.get("/dashboard", response_class=HTMLResponse) +def get_dashboard(): + global request_count + request_count += 1 + + uptime = round(time.time() - start_time, 2) + + html_content = f""" + + + + + Ghaymah SRE Dashboard + + + + +
+

🚀 Ghaymah SRE Live Monitoring Dashboard

+

تحديث تلقائي كل 5 ثوانٍ

+
+
+

الحالة (Status)

+

UP (200 OK)

+
+
+

مدة التشغيل (Uptime)

+

{uptime}s

+
+
+

عدد الطلبات (Total Requests)

+

{request_count}

+
+
+
+ + + """ + return html_content diff --git a/q1-deploy-monitor/app.py b/q1-deploy-monitor/app.py index 60c3832..94852b6 100644 --- a/q1-deploy-monitor/app.py +++ b/q1-deploy-monitor/app.py @@ -1,24 +1,74 @@ from fastapi import FastAPI +from fastapi.responses import HTMLResponse import time app = FastAPI() + start_time = time.time() request_count = 0 -@app.middleware("http") -def count_requests(request, call_next): +@app.get("/") +def read_root(): 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(): +def health_check(): + global request_count + request_count += 1 return { - "status": "healthy", + "status": "ok", "uptime_seconds": round(time.time() - start_time, 2), "total_requests": request_count } + +@app.get("/dashboard", response_class=HTMLResponse) +def get_dashboard(): + global request_count + request_count += 1 + + uptime = round(time.time() - start_time, 2) + + html_content = f""" + + + + + Ghaymah SRE Dashboard + + + + +
+

🚀 Ghaymah SRE Live Monitoring Dashboard

+

تحديث تلقائي كل 5 ثوانٍ

+
+
+

الحالة (Status)

+

UP (200 OK)

+
+
+

مدة التشغيل (Uptime)

+

{uptime}s

+
+
+

عدد الطلبات (Total Requests)

+

{request_count}

+
+
+
+ + + """ + return html_content