Complete Task 1: Deploy and Monitoring
هذا الالتزام موجود في:
50
q1-deploy-monitor/static/script.js
Normal file
50
q1-deploy-monitor/static/script.js
Normal file
@@ -0,0 +1,50 @@
|
||||
async function loadStats() {
|
||||
try {
|
||||
const response = await fetch("/stats");
|
||||
const data = await response.json();
|
||||
|
||||
// Service Status
|
||||
const statusElement = document.getElementById("status");
|
||||
|
||||
if (data.status === "healthy") {
|
||||
statusElement.textContent = "🟢 Healthy";
|
||||
statusElement.style.color = "green";
|
||||
} else {
|
||||
statusElement.textContent = "🔴 Down";
|
||||
statusElement.style.color = "red";
|
||||
}
|
||||
|
||||
// Response Time
|
||||
const responseElement = document.getElementById("response-time");
|
||||
responseElement.textContent = data.response_time_ms + " ms";
|
||||
|
||||
if (data.response_time_ms < 100) {
|
||||
responseElement.style.color = "green";
|
||||
} else {
|
||||
responseElement.style.color = "orange";
|
||||
}
|
||||
|
||||
// Request Count
|
||||
document.getElementById("requests").textContent = data.requests;
|
||||
|
||||
// Uptime
|
||||
const minutes = Math.floor(data.uptime_seconds / 60);
|
||||
const seconds = data.uptime_seconds % 60;
|
||||
|
||||
document.getElementById("uptime").textContent =
|
||||
`${minutes} min ${seconds} sec`;
|
||||
|
||||
} catch (error) {
|
||||
|
||||
const statusElement = document.getElementById("status");
|
||||
statusElement.textContent = "🔴 Down";
|
||||
statusElement.style.color = "red";
|
||||
|
||||
document.getElementById("response-time").textContent = "--";
|
||||
document.getElementById("requests").textContent = "--";
|
||||
document.getElementById("uptime").textContent = "--";
|
||||
}
|
||||
}
|
||||
|
||||
loadStats();
|
||||
setInterval(loadStats, 5000);
|
||||
52
q1-deploy-monitor/static/style.css
Normal file
52
q1-deploy-monitor/static/style.css
Normal file
@@ -0,0 +1,52 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: #f5f7fa;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 90%;
|
||||
max-width: 700px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 30px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: white;
|
||||
margin: 15px 0;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
border-left: 5px solid #007bff;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
color: #555;
|
||||
margin-bottom: 10px;
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.card p {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
color: #007bff;
|
||||
}
|
||||
|
||||
.refresh {
|
||||
margin-top: 20px;
|
||||
color: #777;
|
||||
font-size: 15px;
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم