271 lines
16 KiB
HTML
271 lines
16 KiB
HTML
<!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">
|
||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500&family=Geist+Mono:wght@400;500&display=swap">
|
||
<style>
|
||
:root {
|
||
--bg: #141415; --card: #19191b; --raised: #232325; --line: rgba(237,237,237,.08);
|
||
--text: #ededed; --text2: #a1a1a6; --muted: #85858b;
|
||
--accent: #ff2e93;
|
||
--ok: #4cc38a; --warn: #d9a441; --bad: #e5484d;
|
||
--ease: cubic-bezier(.22, 1, .36, 1);
|
||
--mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
|
||
}
|
||
* { box-sizing: border-box; margin: 0; }
|
||
body { background: var(--bg); color: var(--text); font: 400 14px/20px "Geist", -apple-system, "Inter", "Segoe UI", sans-serif; padding: 32px 24px 64px; }
|
||
.wrap { max-width: 1440px; margin: 0 auto; }
|
||
header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
|
||
h1 { font-size: 18px; line-height: 24px; font-weight: 500; }
|
||
.pill { display: inline-flex; align-items: center; gap: 8px; font: 400 12px/16px var(--mono); color: var(--text2); }
|
||
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
|
||
.pill.bad::before { background: var(--bad); }
|
||
.spacer { flex: 1; }
|
||
.clock { color: var(--muted); font: 400 12px/16px var(--mono); font-variant-numeric: tabular-nums; }
|
||
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
|
||
.seg button { background: none; border: 0; color: var(--muted); height: 28px; padding: 0 12px; border-radius: 8px; cursor: pointer; font: inherit; transition: color 150ms var(--ease), background-color 150ms var(--ease); }
|
||
.seg button:hover { color: var(--text); }
|
||
.seg button.on { background: var(--raised); color: var(--text); box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
|
||
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
||
h2 { font-size: 13px; line-height: 20px; font-weight: 500; color: var(--text2); margin: 40px 0 12px; }
|
||
|
||
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
|
||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 16px; }
|
||
@media (max-width: 480px) { .grid { grid-template-columns: 1fr; } }
|
||
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
|
||
.card.off { opacity: .55; }
|
||
.label { font-size: 12px; line-height: 16px; color: var(--muted); }
|
||
.big { font-size: 28px; line-height: 36px; font-weight: 500; font-variant-numeric: tabular-nums; margin-top: 4px; }
|
||
.big small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 4px; }
|
||
.sub { color: var(--muted); font-size: 12px; line-height: 16px; margin-top: 4px; font-variant-numeric: tabular-nums; }
|
||
|
||
.nodehead { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
|
||
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
|
||
.off .dot { background: var(--bad); }
|
||
.nodename { font-weight: 500; font-size: 16px; line-height: 24px; }
|
||
.ip { color: var(--muted); font: 400 12px/16px var(--mono); margin-left: auto; font-variant-numeric: tabular-nums; }
|
||
.nodebody { display: grid; grid-template-columns: 160px 1fr; gap: 24px; }
|
||
@media (max-width: 480px) { .nodebody { grid-template-columns: 1fr; } }
|
||
.temp { font-size: 32px; line-height: 40px; font-weight: 500; font-variant-numeric: tabular-nums; margin-top: 4px; }
|
||
.temp small { font-size: 14px; color: var(--muted); font-weight: 400; }
|
||
.spark { width: 100%; height: 56px; margin-top: 8px; display: block; }
|
||
|
||
.bar { margin-bottom: 12px; }
|
||
.bar:last-child { margin-bottom: 0; }
|
||
.bar .row { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; line-height: 16px; margin-bottom: 4px; }
|
||
.bar .row b { font-weight: 400; color: var(--muted); }
|
||
.bar .row span { font-variant-numeric: tabular-nums; color: var(--text2); }
|
||
.track { height: 4px; background: var(--raised); border-radius: 2px; overflow: hidden; }
|
||
.fill { height: 100%; background: var(--accent); border-radius: 2px; }
|
||
.fill.warn { background: var(--warn); } .fill.bad { background: var(--bad); }
|
||
.foot { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font: 400 12px/16px var(--mono); font-variant-numeric: tabular-nums; }
|
||
|
||
table { width: 100%; border-collapse: collapse; font-size: 13px; line-height: 20px; }
|
||
th { text-align: left; font-size: 12px; line-height: 16px; color: var(--muted); font-weight: 400; padding: 8px 12px; }
|
||
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; transition: color 150ms var(--ease); }
|
||
th.sortable:hover { color: var(--text); }
|
||
th svg { width: 12px; height: 12px; margin-left: 4px; vertical-align: -2px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
|
||
td { padding: 8px 12px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
|
||
tr:hover td { background: rgba(237,237,237,.02); }
|
||
.tablecard { padding: 8px; overflow-x: auto; }
|
||
.tag { font: 400 11px/16px var(--mono); padding: 0 6px; border-radius: 4px; background: var(--raised); color: var(--text2); }
|
||
.st { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 8px; }
|
||
.st.running { background: var(--ok); } .st.stopped { background: var(--bad); }
|
||
.mini { width: 72px; display: inline-block; vertical-align: middle; }
|
||
#err { display: none; margin-bottom: 16px; padding: 12px 16px; border-radius: 10px; background: rgba(229,72,77,.08); border: 1px solid rgba(229,72,77,.24); 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 et 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 ARROW_UP = '<svg viewBox="0 0 24 24"><path d="m5 12 7-7 7 7M12 19V5"/></svg>';
|
||
const ARROW_DOWN = '<svg viewBox="0 0 24 24"><path d="M12 5v14m7-7-7 7-7-7"/></svg>';
|
||
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) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[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)}`);
|
||
return `<svg class="spark" viewBox="0 0 ${W} ${H}" preserveAspectRatio="none">
|
||
<line x1="0" x2="${W}" y1="0.5" y2="0.5" stroke="rgba(237,237,237,.08)" vector-effect="non-scaling-stroke"/>
|
||
<line x1="0" x2="${W}" y1="${H / 2}" y2="${H / 2}" stroke="rgba(237,237,237,.08)" vector-effect="non-scaling-stroke"/>
|
||
<line x1="0" x2="${W}" y1="${H - 0.5}" y2="${H - 0.5}" stroke="rgba(237,237,237,.08)" vector-effect="non-scaling-stroke"/>
|
||
<polyline points="${xy.join(' ')}" fill="none" stroke="#ff2e93" stroke-width="1.5" vector-effect="non-scaling-stroke" stroke-linejoin="round" stroke-linecap="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} actifs</span>
|
||
${n.pveVersion ? `<span>${esc(n.pveVersion.replace('pve-manager/', 'PVE ').split('/')[0])}</span>` : ''}
|
||
</div>
|
||
${n.cpuModel ? `<div class="sub" style="margin-top:8px">${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 ? ARROW_UP : ARROW_DOWN) : ''}</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:${Math.min(100, p).toFixed(1)}%"></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>
|