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);
|
||||
المرجع في مشكلة جديدة
حظر مستخدم