73 أسطر
2.2 KiB
Python
73 أسطر
2.2 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.responses import HTMLResponse
|
|
import uvicorn
|
|
import time
|
|
|
|
app = FastAPI()
|
|
|
|
start_time = time.time()
|
|
request_count = 0
|
|
|
|
@app.get("/")
|
|
def read_root():
|
|
global request_count
|
|
request_count += 1
|
|
return {"message": "Welcome to Ghaymah SRE Service"}
|
|
|
|
@app.get("/health")
|
|
def health_check():
|
|
global request_count
|
|
request_count += 1
|
|
return {
|
|
"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)
|
|
|
|
return 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; }}
|
|
.status-up {{ color: #22c55e; font-weight: bold; }}
|
|
h1 {{ font-size: 2.5rem; color: #38bdf8; }}
|
|
</style>
|
|
<script>setTimeout(() => {{ window.location.reload(); }}, 5000);</script>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h2>🚀 Ghaymah SRE Live Monitoring Dashboard</h2>
|
|
<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>
|
|
"""
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|