add files
هذا الالتزام موجود في:
88
app.py
Normal file
88
app.py
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
from flask import Flask
|
||||||
|
import time
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
request_count = 0
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
def count_requests():
|
||||||
|
global request_count
|
||||||
|
request_count += 1
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def home():
|
||||||
|
return f"""
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Ghaymah Systems API</title>
|
||||||
|
<style>
|
||||||
|
body {{
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background: #f4f4f4;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.card {{
|
||||||
|
background: white;
|
||||||
|
padding: 40px;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
|
||||||
|
text-align: center;
|
||||||
|
}}
|
||||||
|
|
||||||
|
h1 {{
|
||||||
|
color: #2c3e50;
|
||||||
|
}}
|
||||||
|
|
||||||
|
p {{
|
||||||
|
color: #555;
|
||||||
|
font-size: 18px;
|
||||||
|
}}
|
||||||
|
|
||||||
|
a {{
|
||||||
|
display: inline-block;
|
||||||
|
margin-top: 20px;
|
||||||
|
padding: 10px 20px;
|
||||||
|
background: #007BFF;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 5px;
|
||||||
|
}}
|
||||||
|
|
||||||
|
a:hover {{
|
||||||
|
background: #0056b3;
|
||||||
|
}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h1>🚀 Ghaymah Systems API</h1>
|
||||||
|
|
||||||
|
<p>The API is running successfully.</p>
|
||||||
|
|
||||||
|
<p><strong>Total Requests:</strong> {request_count}</p>
|
||||||
|
|
||||||
|
<a href="/health">Health Check</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
@app.route("/health")
|
||||||
|
def health():
|
||||||
|
return {
|
||||||
|
"status": "healthy",
|
||||||
|
"timestamp": int(time.time()),
|
||||||
|
"requests": request_count
|
||||||
|
}
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host="0.0.0.0", port=5000)
|
||||||
13
q1-deploy-monitor/Dockerfile
Normal file
13
q1-deploy-monitor/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY app.py .
|
||||||
|
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
CMD ["python", "app.py"]
|
||||||
92
q1-deploy-monitor/dashboard.html
Normal file
92
q1-deploy-monitor/dashboard.html
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Ghaymah SRE Dashboard</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body{
|
||||||
|
font-family:Arial,sans-serif;
|
||||||
|
background:#f4f4f4;
|
||||||
|
margin:40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container{
|
||||||
|
max-width:700px;
|
||||||
|
margin:auto;
|
||||||
|
background:white;
|
||||||
|
padding:20px;
|
||||||
|
border-radius:10px;
|
||||||
|
box-shadow:0 0 10px rgba(0,0,0,.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card{
|
||||||
|
margin:15px 0;
|
||||||
|
padding:15px;
|
||||||
|
border-radius:8px;
|
||||||
|
background:#fafafa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value{
|
||||||
|
font-size:28px;
|
||||||
|
font-weight:bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<h2>Ghaymah API Monitoring Dashboard</h2>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>Status</h3>
|
||||||
|
<div id="status" class="value">Checking...</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>Latency</h3>
|
||||||
|
<div id="latency" class="value">-- ms</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>Total Requests</h3>
|
||||||
|
<div id="requests" class="value">0</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
async function update(){
|
||||||
|
|
||||||
|
const start=performance.now();
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
const response=await fetch("http://localhost:5000/health");
|
||||||
|
const data=await response.json();
|
||||||
|
|
||||||
|
const latency=(performance.now()-start).toFixed(2);
|
||||||
|
|
||||||
|
document.getElementById("status").innerHTML="🟢 UP";
|
||||||
|
document.getElementById("latency").innerHTML=latency+" ms";
|
||||||
|
document.getElementById("requests").innerHTML=data.requests;
|
||||||
|
|
||||||
|
}catch(e){
|
||||||
|
|
||||||
|
document.getElementById("status").innerHTML="🔴 DOWN";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
setInterval(update,30000);
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
22
q1-deploy-monitor/health-check.sh
Executable file
22
q1-deploy-monitor/health-check.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
URL="http://localhost:5000/health"
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
START=$(date +%s%3N)
|
||||||
|
|
||||||
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
|
||||||
|
|
||||||
|
END=$(date +%s%3N)
|
||||||
|
|
||||||
|
LATENCY=$((END-START))
|
||||||
|
|
||||||
|
if [ "$STATUS" -eq 200 ]; then
|
||||||
|
echo "$(date) | UP | ${LATENCY}ms"
|
||||||
|
else
|
||||||
|
echo "$(date) | DOWN"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 30
|
||||||
|
done
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
Flask==3.0.3
|
||||||
|
gunicorn==23.0.0
|
||||||
المرجع في مشكلة جديدة
حظر مستخدم