Files
Dashboard/public/index.html
T
2026-11-01 19:47:10 +01:00

258 lines
15 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Proxmox Dashboard</title>
<link rel="icon" type="image/png" href="https://sunshine.li/uploads/ethansun/S.png">
<link rel="apple-touch-icon" href="https://sunshine.li/uploads/ethansun/S.png">
<style>
:root {
--bg: #07070a; --card: #101015; --card2: #16161d; --line: #23232d;
--text: #f2f2f5; --muted: #8a8a98; --pink: #ff2e93; --pink2: #ff7ac0;
--ok: #34d399; --warn: #fbbf24; --bad: #f87171;
--r: 18px;
}
* { box-sizing: border-box; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 -apple-system, "Inter", "Segoe UI", sans-serif; padding: 24px 16px 48px; }
.wrap { max-width: 1400px; margin: 0 auto; }
header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
h1 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: rgba(52,211,153,.12); color: var(--ok); border: 1px solid rgba(52,211,153,.3); }
.pill.bad { background: rgba(248,113,113,.12); color: var(--bad); border-color: rgba(248,113,113,.3); }
.spacer { flex: 1; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg button { background: none; border: 0; color: var(--muted); padding: 4px 12px; border-radius: 8px; cursor: pointer; font: inherit; }
.seg button.on { background: #2a2a35; color: var(--text); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
@media (max-width: 480px) { .grid { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: 0 0 0 1px rgba(255,255,255,.02) inset; }
.card.off { opacity: .55; }
.label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.big small { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.nodehead { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.off .dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.nodename { font-weight: 700; font-size: 16px; }
.ip { color: var(--muted); font-size: 12px; margin-left: auto; font-variant-numeric: tabular-nums; }
.nodebody { display: grid; grid-template-columns: 150px 1fr; gap: 18px; }
@media (max-width: 480px) { .nodebody { grid-template-columns: 1fr; } }
.temp { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.temp small { font-size: 14px; color: var(--muted); font-weight: 500; }
.spark { width: 100%; height: 56px; margin-top: 8px; display: block; }
.bar { margin-bottom: 9px; }
.bar .row { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.bar .row b { font-weight: 500; color: var(--muted); }
.bar .row span { font-variant-numeric: tabular-nums; }
.track { height: 5px; background: #24242e; border-radius: 9px; overflow: hidden; }
.fill { height: 100%; background: linear-gradient(90deg, var(--pink), var(--pink2)); border-radius: 9px; transition: width .6s; }
.fill.warn { background: var(--warn); } .fill.bad { background: var(--bad); }
.foot { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 6px 10px; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
td { padding: 8px 10px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.tablecard { padding: 8px 8px; overflow-x: auto; }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 6px; background: #22222c; color: var(--muted); }
.st { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.st.running { background: var(--ok); } .st.stopped { background: var(--bad); }
.mini { width: 70px; display: inline-block; vertical-align: middle; }
#err { display: none; margin-bottom: 14px; padding: 10px 14px; border-radius: 12px; background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.3); color: var(--bad); }
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>proxmox</h1>
<span class="pill" id="clusterPill">…</span>
<span class="spacer"></span>
<div class="seg" id="range">
<button data-r="3600" class="on">1h</button>
<button data-r="86400">24h</button>
<button data-r="172800">48h</button>
</div>
<span class="clock" id="clock"></span>
</header>
<div id="err"></div>
<div class="totals" id="totals"></div>
<h2>Nodes</h2>
<div class="grid" id="nodes"></div>
<h2>VM &amp; conteneurs</h2>
<div class="card tablecard"><table id="guests"></table></div>
<h2>Stockage</h2>
<div class="card tablecard"><table id="storage"></table></div>
</div>
<script>
const $ = (id) => document.getElementById(id);
let range = 3600, data = null, hist = {};
let sort = { key: 'vmid', dir: 1 };
try { const s = JSON.parse(localStorage.getItem('guestSort')); if (s && s.key) sort = s; } catch {}
const fmtBytes = (b) => {
if (b == null) return '–';
const u = ['o', 'Ko', 'Mo', 'Go', 'To']; let i = 0;
while (b >= 1024 && i < u.length - 1) { b /= 1024; i++; }
return b.toFixed(b >= 100 || i < 2 ? 0 : 1) + ' ' + u[i];
};
const fmtUp = (s) => {
if (!s) return '–';
const d = Math.floor(s / 86400), h = Math.floor(s % 86400 / 3600), m = Math.floor(s % 3600 / 60);
return d ? `${d}j ${h}h` : h ? `${h}h ${m}m` : `${m}m`;
};
const pct = (a, b) => (a == null || !b ? 0 : a / b * 100);
const cls = (p) => p >= 90 ? 'bad' : p >= 75 ? 'warn' : '';
const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
function bar(label, p, text) {
return `<div class="bar"><div class="row"><b>${label}</b><span>${text}</span></div>
<div class="track"><div class="fill ${cls(p)}" style="width:${Math.min(100, p).toFixed(1)}%"></div></div></div>`;
}
function spark(points, idx, min, max) {
const pts = points.filter((p) => p[idx] != null);
if (pts.length < 2) return '<svg class="spark"></svg>';
const t0 = pts[0][0], t1 = pts[pts.length - 1][0] || t0 + 1;
const vals = pts.map((p) => p[idx]);
const lo = min ?? Math.min(...vals) - 2, hi = max ?? Math.max(...vals) + 2;
const W = 300, H = 56;
const xy = pts.map((p) => `${((p[0] - t0) / (t1 - t0 || 1) * W).toFixed(1)},${(H - (p[idx] - lo) / (hi - lo || 1) * (H - 4) - 2).toFixed(1)}`);
const id = 'g' + idx + Math.random().toString(36).slice(2, 6);
return `<svg class="spark" viewBox="0 0 ${W} ${H}" preserveAspectRatio="none">
<defs><linearGradient id="${id}" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#ff2e93" stop-opacity=".35"/><stop offset="1" stop-color="#ff2e93" stop-opacity="0"/></linearGradient></defs>
<polygon points="0,${H} ${xy.join(' ')} ${W},${H}" fill="url(#${id})"/>
<polyline points="${xy.join(' ')}" fill="none" stroke="#ff2e93" stroke-width="1.8" vector-effect="non-scaling-stroke" stroke-linejoin="round"/></svg>`;
}
function render() {
if (!data) return;
$('err').style.display = data.ok ? 'none' : 'block';
if (!data.ok) $('err').textContent = 'Erreur API Proxmox : ' + (data.error || 'inconnue');
if (!data.nodes) return;
const c = data.cluster;
const online = data.nodes.filter((n) => n.online).length;
const pill = $('clusterPill');
pill.textContent = `${c.name || 'cluster'} · ${online}/${data.nodes.length} en ligne`;
pill.className = 'pill' + (online < data.nodes.length || c.quorate === false ? ' bad' : '');
// totaux
const on = data.nodes.filter((n) => n.online);
const sum = (k) => on.reduce((a, n) => a + (n[k] || 0), 0);
const cpuAvg = on.length ? on.reduce((a, n) => a + (n.cpu || 0), 0) / on.length * 100 : 0;
const temps = on.map((n) => n.temp).filter((t) => t != null);
const running = data.guests.filter((g) => g.status === 'running').length;
$('totals').innerHTML = [
['CPU moyen', cpuAvg.toFixed(1) + '<small>%</small>', `${sum('maxcpu')} cœurs au total`],
['RAM', fmtBytes(sum('mem')), `sur ${fmtBytes(sum('maxmem'))} · ${pct(sum('mem'), sum('maxmem')).toFixed(0)}%`],
['Temp. max', temps.length ? Math.max(...temps).toFixed(1) + '<small>°C</small>' : '–', temps.length ? `moy. ${(temps.reduce((a, b) => a + b, 0) / temps.length).toFixed(1)}°C` : 'node_exporter ?'],
['Invités actifs', `${running}<small>/ ${data.guests.length}</small>`, `${data.guests.filter((g) => g.type === 'qemu').length} VM · ${data.guests.filter((g) => g.type === 'lxc').length} LXC`],
].map(([l, v, s]) => `<div class="card"><div class="label">${l}</div><div class="big">${v}</div><div class="sub">${s}</div></div>`).join('');
// nodes
$('nodes').innerHTML = data.nodes.map((n) => {
const h = hist[n.name] || [];
const cpuP = (n.cpu || 0) * 100, memP = pct(n.mem, n.maxmem), diskP = pct(n.disk, n.maxdisk);
const guests = data.guests.filter((g) => g.node === n.name && g.status === 'running').length;
return `<div class="card ${n.online ? '' : 'off'}">
<div class="nodehead"><span class="dot"></span><span class="nodename">${esc(n.name)}</span>
<span class="ip">${esc(n.ip || '')}</span></div>
<div class="nodebody">
<div>
<div class="label">Température</div>
<div class="temp">${n.temp != null ? n.temp.toFixed(1) + '<small> °C</small>' : '<small>n/a</small>'}</div>
${spark(h, 3)}
</div>
<div>
${bar('CPU' + (n.maxcpu ? ` · ${n.maxcpu} cœurs` : ''), cpuP, cpuP.toFixed(1) + ' %')}
${bar('RAM', memP, `${fmtBytes(n.mem)} / ${fmtBytes(n.maxmem)}`)}
${bar(esc(n.diskLabel || 'Disque'), diskP, `${fmtBytes(n.disk)} / ${fmtBytes(n.maxdisk)}`)}
${n.swapMax ? bar('Swap', pct(n.swap, n.swapMax), `${fmtBytes(n.swap)} / ${fmtBytes(n.swapMax)}`) : ''}
</div>
</div>
<div class="foot">
<span>up ${fmtUp(n.uptime)}</span>
<span>load ${n.load ? n.load.map((x) => x.toFixed(2)).join(' ') : '–'}</span>
<span>${guests} invité(s) actif(s)</span>
${n.pveVersion ? `<span>${esc(n.pveVersion.replace('pve-manager/', 'PVE ').split('/')[0])}</span>` : ''}
</div>
${n.cpuModel ? `<div class="sub" style="margin-top:6px">${esc(n.cpuModel)}</div>` : ''}
</div>`;
}).join('');
// invités
const cols = [['vmid', 'ID'], ['name', 'Nom'], ['type', 'Type'], ['node', 'Node'], ['status', 'État'], ['cpu', 'CPU'], ['mem', 'RAM'], ['uptime', 'Uptime']];
const th = cols.map(([k, l]) => `<th class="sortable" data-k="${k}">${l}${sort.key === k ? (sort.dir > 0 ? ' ▲' : ' ▼') : ''}</th>`).join('');
const sortedGuests = [...data.guests].sort((a, b) => {
let x = a[sort.key], y = b[sort.key];
// valeurs vides (VM arrêtées) toujours en bas
const xe = x == null || (['cpu', 'mem', 'uptime'].includes(sort.key) && a.status !== 'running');
const ye = y == null || (['cpu', 'mem', 'uptime'].includes(sort.key) && b.status !== 'running');
if (xe !== ye) return xe ? 1 : -1;
if (xe && ye) return 0;
const r = typeof x === 'number' && typeof y === 'number' ? x - y : String(x).localeCompare(String(y), 'fr', { numeric: true });
return (r || a.vmid - b.vmid) * sort.dir;
});
$('guests').innerHTML = `<tr>${th}</tr>` +
sortedGuests.map((g) => `<tr><td>${g.vmid}</td><td>${esc(g.name)}</td><td><span class="tag">${g.type === 'qemu' ? 'VM' : 'LXC'}</span></td>
<td>${esc(g.node)}</td><td><span class="st ${g.status}"></span>${esc(g.status)}</td>
<td>${g.status === 'running' ? (g.cpu * 100).toFixed(1) + ' %' : '–'}</td>
<td>${g.status === 'running' ? `${fmtBytes(g.mem)} / ${fmtBytes(g.maxmem)}` : fmtBytes(g.maxmem)}</td>
<td>${g.status === 'running' ? fmtUp(g.uptime) : '–'}</td></tr>`).join('');
// stockage
$('storage').innerHTML = `<tr><th>Nom</th><th>Node</th><th>Type</th><th>Usage</th><th></th></tr>` +
data.storage.sort((a, b) => a.id.localeCompare(b.id) || a.node.localeCompare(b.node)).map((s) => {
const p = pct(s.disk, s.maxdisk);
return `<tr><td>${esc(s.id)}</td><td>${s.shared ? '<span class="tag">partagé</span>' : esc(s.node)}</td><td>${esc(s.plugintype || '')}</td>
<td>${fmtBytes(s.disk)} / ${fmtBytes(s.maxdisk)} · ${p.toFixed(0)}%</td>
<td><div class="track mini"><div class="fill ${cls(p)}" style="width:${p}%"></div></div></td></tr>`;
}).join('');
}
async function loadOverview() {
try { data = await (await fetch('/api/overview', { cache: 'no-store' })).json(); }
catch { data = { ok: false, error: 'dashboard injoignable', nodes: data?.nodes, guests: data?.guests, storage: data?.storage, cluster: data?.cluster }; }
render();
}
async function loadHistory() {
try { hist = await (await fetch('/api/history?range=' + range, { cache: 'no-store' })).json(); render(); } catch {}
}
$('guests').addEventListener('click', (e) => {
const k = e.target.closest('th.sortable')?.dataset.k;
if (!k) return;
// CPU / RAM / Uptime : décroissant au premier clic, le reste croissant
sort = sort.key === k ? { key: k, dir: -sort.dir } : { key: k, dir: ['cpu', 'mem', 'uptime'].includes(k) ? -1 : 1 };
try { localStorage.setItem('guestSort', JSON.stringify(sort)); } catch {}
render();
});
$('range').addEventListener('click', (e) => {
if (!e.target.dataset.r) return;
range = +e.target.dataset.r;
[...$('range').children].forEach((b) => b.classList.toggle('on', b === e.target));
loadHistory();
});
setInterval(() => { $('clock').textContent = new Date().toLocaleString('fr-FR', { weekday: 'short', day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit', second: '2-digit' }); }, 1000);
loadOverview(); loadHistory();
setInterval(loadOverview, 5000);
setInterval(loadHistory, 30000);
</script>
</body>
</html>