Serve live Dashboard directly from FastAPI on /dashboard

هذا الالتزام موجود في:
2026-07-26 15:37:55 +03:00
الأصل ead769611f
التزام 10106651a4
2 ملفات معدلة مع 116 إضافات و16 حذوفات

66
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"""
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>Ghaymah SRE Dashboard</title>
<style>
body {{ font-family: system-ui, sans-serif; background: #0f172a; color: #fff; padding: 40px; text-align: center; }}
.container {{ max-width: 800px; margin: 0 auto; }}
.grid {{ display: flex; gap: 20px; margin-top: 30px; }}
.card {{ background: #1e293b; padding: 25px; border-radius: 12px; flex: 1; border: 1px solid #334155; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }}
.status-up {{ color: #22c55e; font-weight: bold; }}
h1 {{ font-size: 2.5rem; margin-top: 10px; color: #38bdf8; }}
p {{ color: #94a3b8; }}
</style>
<script>
setTimeout(() => {{ window.location.reload(); }}, 5000);
</script>
</head>
<body>
<div class="container">
<h2>🚀 Ghaymah SRE Live Monitoring Dashboard</h2>
<p>تحديث تلقائي كل 5 ثوانٍ</p>
<div class="grid">
<div class="card">
<h3>الحالة (Status)</h3>
<h1 class="status-up">UP (200 OK)</h1>
</div>
<div class="card">
<h3>مدة التشغيل (Uptime)</h3>
<h1>{uptime}s</h1>
</div>
<div class="card">
<h3>عدد الطلبات (Total Requests)</h3>
<h1>{request_count}</h1>
</div>
</div>
</div>
</body>
</html>
"""
return html_content

عرض الملف

@@ -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"""
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>Ghaymah SRE Dashboard</title>
<style>
body {{ font-family: system-ui, sans-serif; background: #0f172a; color: #fff; padding: 40px; text-align: center; }}
.container {{ max-width: 800px; margin: 0 auto; }}
.grid {{ display: flex; gap: 20px; margin-top: 30px; }}
.card {{ background: #1e293b; padding: 25px; border-radius: 12px; flex: 1; border: 1px solid #334155; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }}
.status-up {{ color: #22c55e; font-weight: bold; }}
h1 {{ font-size: 2.5rem; margin-top: 10px; color: #38bdf8; }}
p {{ color: #94a3b8; }}
</style>
<script>
setTimeout(() => {{ window.location.reload(); }}, 5000);
</script>
</head>
<body>
<div class="container">
<h2>🚀 Ghaymah SRE Live Monitoring Dashboard</h2>
<p>تحديث تلقائي كل 5 ثوانٍ</p>
<div class="grid">
<div class="card">
<h3>الحالة (Status)</h3>
<h1 class="status-up">UP (200 OK)</h1>
</div>
<div class="card">
<h3>مدة التشغيل (Uptime)</h3>
<h1>{uptime}s</h1>
</div>
<div class="card">
<h3>عدد الطلبات (Total Requests)</h3>
<h1>{request_count}</h1>
</div>
</div>
</div>
</body>
</html>
"""
return html_content