Complete all exam tasks
هذا الالتزام موجود في:
@@ -0,0 +1,13 @@
|
|||||||
|
FROM python:3.12-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||||
|
|||||||
ثنائية
q1-deploy-monitor/__pycache__/app.cpython-313.pyc
Normal file
ثنائية
q1-deploy-monitor/__pycache__/app.cpython-313.pyc
Normal file
ملف ثنائي غير معروض.
40
q1-deploy-monitor/app.py
Normal file
40
q1-deploy-monitor/app.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from fastapi import FastAPI
|
||||||
|
import time
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
request_count = 0
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def home():
|
||||||
|
global request_count
|
||||||
|
request_count += 1
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "Application is running"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health")
|
||||||
|
def health():
|
||||||
|
return {
|
||||||
|
"status": "UP"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/stats")
|
||||||
|
def stats():
|
||||||
|
global request_count
|
||||||
|
|
||||||
|
start = time.time()
|
||||||
|
|
||||||
|
request_count += 1
|
||||||
|
|
||||||
|
response_time = round((time.time() - start) * 1000, 2)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": "UP",
|
||||||
|
"requests": request_count,
|
||||||
|
"response_time": response_time
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Application Dashboard</title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body{
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background:#f4f4f4;
|
||||||
|
text-align:center;
|
||||||
|
margin-top:50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card{
|
||||||
|
width:400px;
|
||||||
|
margin:auto;
|
||||||
|
background:white;
|
||||||
|
padding:25px;
|
||||||
|
border-radius:12px;
|
||||||
|
box-shadow:0 0 10px rgba(0,0,0,0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
h1{
|
||||||
|
color:#333;
|
||||||
|
}
|
||||||
|
|
||||||
|
p{
|
||||||
|
font-size:22px;
|
||||||
|
margin:15px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
span{
|
||||||
|
font-weight:bold;
|
||||||
|
color:green;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
|
||||||
|
<h1>Application Dashboard</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Status:
|
||||||
|
<span id="status">Loading...</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Requests:
|
||||||
|
<span id="requests">0</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Response Time:
|
||||||
|
<span id="response">0</span> ms
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
async function updateDashboard() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
const response = await fetch("http://127.0.0.1:8000/stats");
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
document.getElementById("status").textContent = data.status;
|
||||||
|
|
||||||
|
document.getElementById("requests").textContent = data.requests;
|
||||||
|
|
||||||
|
document.getElementById("response").textContent = data.response_time;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(error){
|
||||||
|
|
||||||
|
document.getElementById("status").textContent = "DOWN";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDashboard();
|
||||||
|
|
||||||
|
setInterval(updateDashboard,30000);
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|||||||
16
q1-deploy-monitor/health-check.sh
Normal file → Executable file
16
q1-deploy-monitor/health-check.sh
Normal file → Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
URL="http://localhost:8000/health"
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
response=$(curl -s -o /dev/null -w "%{http_code}" $URL)
|
||||||
|
|
||||||
|
if [ "$response" -eq 200 ]; then
|
||||||
|
echo "$(date): Application is UP"
|
||||||
|
else
|
||||||
|
echo "$(date): Application is DOWN"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 30
|
||||||
|
done
|
||||||
|
|||||||
2
q1-deploy-monitor/requirements.txt
Normal file
2
q1-deploy-monitor/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fastapi
|
||||||
|
uvicorn
|
||||||
المرجع في مشكلة جديدة
حظر مستخدم