الملفات
ghaymah-exam-AhmedNasser-SRE/q1-deploy-monitor/dashboard.html

172 أسطر
4.3 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Ahmed Nasser SRE Dashboard</title>
<style>
:root {
color-scheme: light;
--bg: #f5f7fb;
--panel: #ffffff;
--text: #102033;
--muted: #5f6b7a;
--border: #dbe3ee;
--accent: #0f766e;
--good: #15803d;
--shadow: 0 12px 30px rgba(16, 32, 51, 0.08);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background: linear-gradient(180deg, #eef3f9 0%, #f8fafc 100%);
color: var(--text);
}
.wrap {
max-width: 960px;
margin: 0 auto;
padding: 40px 20px;
}
.hero {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
padding: 28px;
box-shadow: var(--shadow);
}
h1 {
margin: 0 0 8px;
font-size: 32px;
}
.subtitle {
margin: 0;
color: var(--muted);
}
.status {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 20px;
padding: 8px 12px;
border-radius: 999px;
background: #ecfdf5;
color: var(--good);
font-weight: 700;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
margin-top: 20px;
}
.card {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 14px;
padding: 18px;
box-shadow: var(--shadow);
}
.label {
color: var(--muted);
font-size: 14px;
margin-bottom: 10px;
}
.value {
font-size: 28px;
font-weight: 700;
word-break: break-word;
}
.timestamp {
margin-top: 16px;
color: var(--muted);
font-size: 14px;
}
</style>
</head>
<body>
<main class="wrap">
<section class="hero">
<h1>Ahmed Nasser SRE Dashboard</h1>
<p class="subtitle">Live API metrics from /metrics</p>
<div id="status" class="status">Loading...</div>
<div class="grid">
<div class="card">
<div class="label">Current Status</div>
<div id="currentStatus" class="value">-</div>
</div>
<div class="card">
<div class="label">Uptime</div>
<div id="uptime" class="value">-</div>
</div>
<div class="card">
<div class="label">Requests Count</div>
<div id="requests" class="value">-</div>
</div>
<div class="card">
<div class="label">Memory Usage</div>
<div id="memoryUsage" class="value">-</div>
</div>
</div>
<div id="updatedAt" class="timestamp">Last updated: -</div>
</section>
</main>
<script>
const elements = {
status: document.getElementById('status'),
currentStatus: document.getElementById('currentStatus'),
uptime: document.getElementById('uptime'),
requests: document.getElementById('requests'),
memoryUsage: document.getElementById('memoryUsage'),
updatedAt: document.getElementById('updatedAt')
};
const queryParams = new URLSearchParams(window.location.search);
const apiBase = queryParams.get('apiBase') || (window.location.protocol === 'file:' ? 'http://localhost:3000' : '');
function formatSeconds(value) {
return `${value}s`;
}
function formatMegabytes(value) {
return `${value} MB`;
}
async function refreshMetrics() {
try {
const response = await fetch(`${apiBase}/metrics`);
const data = await response.json();
elements.status.textContent = data.status;
elements.currentStatus.textContent = data.status;
elements.uptime.textContent = formatSeconds(data.uptime);
elements.requests.textContent = data.requests;
elements.memoryUsage.textContent = formatMegabytes(data.memoryUsageMB);
elements.updatedAt.textContent = `Last updated: ${new Date(data.timestamp).toLocaleString()}`;
} catch (error) {
elements.status.textContent = 'DOWN';
elements.currentStatus.textContent = 'DOWN';
elements.updatedAt.textContent = 'Last updated: unavailable';
}
}
refreshMetrics();
setInterval(refreshMetrics, 5000);
</script>
</body>
</html>