Complete Ghaymah Internship Assessment
هذا الالتزام موجود في:
24
deploy-monitor/Dockerfile
Normal file
24
deploy-monitor/Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN printf 'from http.server import BaseHTTPRequestHandler, HTTPServer\n\
|
||||
import json\n\
|
||||
class Handler(BaseHTTPRequestHandler):\n\
|
||||
requests = 0\n\
|
||||
def do_GET(self):\n\
|
||||
Handler.requests += 1\n\
|
||||
if self.path == "/health":\n\
|
||||
self.send_response(200)\n\
|
||||
self.send_header("Content-Type","application/json")\n\
|
||||
self.end_headers()\n\
|
||||
self.wfile.write(json.dumps({"status":"UP","requests":Handler.requests}).encode())\n\
|
||||
else:\n\
|
||||
self.send_response(200)\n\
|
||||
self.end_headers()\n\
|
||||
self.wfile.write(b"Hello from Ghaymah!")\n\
|
||||
HTTPServer(("0.0.0.0",8000),Handler).serve_forever()' > app.py
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["python","app.py"]
|
||||
108
deploy-monitor/dashboard.html
Normal file
108
deploy-monitor/dashboard.html
Normal file
@@ -0,0 +1,108 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>API Dashboard</title>
|
||||
|
||||
<style>
|
||||
|
||||
body{
|
||||
font-family:Arial,sans-serif;
|
||||
background:#f5f5f5;
|
||||
text-align:center;
|
||||
margin-top:80px;
|
||||
}
|
||||
|
||||
.card{
|
||||
width:350px;
|
||||
margin:auto;
|
||||
padding:30px;
|
||||
background:white;
|
||||
border-radius:10px;
|
||||
box-shadow:0 0 10px rgba(0,0,0,.2);
|
||||
}
|
||||
|
||||
h2{
|
||||
color:#333;
|
||||
}
|
||||
|
||||
.status{
|
||||
font-size:25px;
|
||||
margin:20px;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.response{
|
||||
font-size:20px;
|
||||
margin:15px;
|
||||
}
|
||||
|
||||
.requests{
|
||||
font-size:20px;
|
||||
margin:15px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="card">
|
||||
|
||||
<h2>API Monitoring Dashboard</h2>
|
||||
|
||||
<div class="status" id="status">Checking...</div>
|
||||
|
||||
<div class="response" id="response"></div>
|
||||
|
||||
<div class="requests" id="requests"></div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
async function checkHealth(){
|
||||
|
||||
let start=performance.now();
|
||||
|
||||
try{
|
||||
|
||||
const res=await fetch("http://localhost:8000/health");
|
||||
|
||||
const data=await res.json();
|
||||
|
||||
let end=performance.now();
|
||||
|
||||
document.getElementById("status").innerHTML="🟢 UP";
|
||||
|
||||
document.getElementById("status").style.color="green";
|
||||
|
||||
document.getElementById("response").innerHTML="Response Time : "+(end-start).toFixed(2)+" ms";
|
||||
|
||||
document.getElementById("requests").innerHTML="Requests : "+data.requests;
|
||||
|
||||
}
|
||||
|
||||
catch{
|
||||
|
||||
document.getElementById("status").innerHTML="🔴 DOWN";
|
||||
|
||||
document.getElementById("status").style.color="red";
|
||||
|
||||
document.getElementById("response").innerHTML="-";
|
||||
|
||||
document.getElementById("requests").innerHTML="-";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
checkHealth();
|
||||
|
||||
setInterval(checkHealth,30000);
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
20
deploy-monitor/health-check.sh
Normal file
20
deploy-monitor/health-check.sh
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
URL="http://localhost:8000/health"
|
||||
|
||||
echo "Starting Health Monitor..."
|
||||
|
||||
while true
|
||||
do
|
||||
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $URL)
|
||||
TIME=$(curl -s -o /dev/null -w "%{time_total}" $URL)
|
||||
DATE=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
|
||||
if [ "$RESPONSE" = "200" ]; then
|
||||
echo "[$DATE] STATUS: UP | HTTP: $RESPONSE | Response Time: ${TIME}s"
|
||||
else
|
||||
echo "[$DATE] STATUS: DOWN | HTTP: $RESPONSE"
|
||||
fi
|
||||
|
||||
sleep 30
|
||||
done
|
||||
المرجع في مشكلة جديدة
حظر مستخدم