Laboratorio doméstico
demo-kit/ es lo que simula el dispositivo para la demostración en la página de inicio. El dispositivo en sí no lo necesita.
demo-kit/ es lo que simula el dispositivo para la demostración en la página de inicio. El dispositivo en sí no lo necesita.
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="color-scheme" content="dark light">
<title>Home lab</title>
<style>
:root {
color-scheme: light dark;
--bg: #f2f5fa; --glow: rgba(29,107,255,.10);
--card: #ffffff; --face: #ffffff; --face2: #f6f8fc; --line: #dfe5ee; --line2: #e9edf4;
--text: #0e1a30; --muted: #5d6b84; --faint: #97a3b8;
--accent: #1d6bff; --accent-ink: #ffffff; --accent-soft: rgba(29,107,255,.10);
--ok: #0fae66; --warn: #e08600; --bad: #e23d4f; --off: #c3ccd9;
--track: #e8edf5; --rack: #e4e9f2; --rack-line: #d3dbe7; --rail: #cdd6e3; --hole: #f4f6fa;
--shadow: 0 1px 2px rgba(14,26,48,.05), 0 10px 28px rgba(14,26,48,.07);
--shadow-face: 0 1px 1px rgba(14,26,48,.05), 0 2px 6px rgba(14,26,48,.05);
--shadow-pull: 0 2px 4px rgba(14,26,48,.06), 0 18px 40px rgba(14,26,48,.18);
--led-glow: 0;
--sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
--mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #070b14; --glow: rgba(77,141,255,.16);
--card: #0d1423; --face: #162036; --face2: #111a2c; --line: rgba(150,172,214,.14); --line2: rgba(150,172,214,.09);
--text: #e8eefa; --muted: #8d9ab3; --faint: #55617a;
--accent: #4d8dff; --accent-ink: #04122e; --accent-soft: rgba(77,141,255,.14);
--ok: #2fdb8b; --warn: #ffb224; --bad: #ff5d70; --off: #2b3650;
--track: #18223a; --rack: #090e1a; --rack-line: rgba(150,172,214,.10); --rail: #18233a; --hole: #04070d;
--shadow: 0 0 0 1px rgba(150,172,214,.08), 0 16px 40px rgba(0,0,0,.45);
--shadow-face: 0 1px 0 rgba(255,255,255,.04) inset, 0 2px 6px rgba(0,0,0,.35);
--shadow-pull: 0 1px 0 rgba(255,255,255,.06) inset, 0 0 0 1px rgba(77,141,255,.35), 0 22px 48px rgba(0,0,0,.65);
--led-glow: 1;
}
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 14px/1.4 var(--sans);
font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
body::before { content: ""; position: fixed; inset: 0; pointer-events: none;
background: radial-gradient(90% 46% at 50% -12%, var(--glow), transparent 70%); }
main { position: relative; max-width: 820px; margin: 0 auto;
padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
h1, h2, p, dl, dd { margin: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
/* ---------- host header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
.brand svg { width: 16px; height: 16px; color: var(--accent); }
.chips { display: flex; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px; font-size: 11.5px; font-weight: 600;
color: var(--muted); background: var(--card); border: 1px solid var(--line); white-space: nowrap; }
.chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.chip.live i { background: var(--ok); animation: blink 2.4s ease-in-out infinite; }
.chip.down { color: var(--warn); } .chip.down i { background: var(--warn); animation: blink .9s ease-in-out infinite; }
.chip.sim { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
@keyframes blink { 50% { opacity: .35 } }
.hostrow { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 12px; }
h1 { font-size: 26px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up { color: var(--muted); font-size: 12.5px; margin-top: 4px; white-space: nowrap; }
.up b { color: var(--text); font-weight: 600; }
.loads { display: flex; gap: 12px; flex: none; }
.loads div { text-align: right; }
.loads b { display: block; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.loads span { display: block; font-size: 10px; color: var(--faint); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
/* ---------- host card: arcs, storage, network ---------- */
.card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 14px 16px 16px; }
.arcs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.arc { text-align: center; min-width: 0; --c: var(--accent); }
.arc.warn { --c: var(--warn); } .arc.crit { --c: var(--bad); } .arc.none { --c: var(--faint); }
.arc.none .v { opacity: 0; }
.dial { position: relative; width: 82px; height: 82px; margin: 0 auto; }
.dial svg { width: 100%; height: 100%; display: block; overflow: visible; }
.dial circle { fill: none; stroke-width: 7; stroke-linecap: round; transform: rotate(135deg); transform-origin: 44px 44px; }
.dial .t { stroke: var(--track); }
.dial .v { stroke: var(--c); transition: stroke-dasharray .9s cubic-bezier(.2,.8,.2,1), stroke .4s; }
.dial .read { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding-bottom: 2px; }
.dial .read b { font-size: 22px; font-weight: 700; letter-spacing: -.03em; }
.dial .read i { font-style: normal; font-size: 11px; font-weight: 600; color: var(--muted); margin: 7px 0 0 1px; }
.arc h2 { font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-top: -8px; }
.arc p { font-size: 11.5px; color: var(--faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line2); }
.split > div { min-width: 0; }
.label { font-size: 10.5px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.disk + .disk { margin-top: 7px; }
.disk .row { display: flex; justify-content: space-between; gap: 6px; font-size: 11.5px; margin-bottom: 3px; }
.disk .row b { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.disk .row span { color: var(--muted); white-space: nowrap; flex: none; }
.bar { height: 4px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width .9s cubic-bezier(.2,.8,.2,1); }
.bar.warn i { background: var(--warn); } .bar.crit i { background: var(--bad); }
.rates { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.rates span { display: inline-flex; align-items: center; gap: 4px; }
.rates svg { width: 10px; height: 10px; }
.rates .rx svg { color: var(--accent); } .rates .tx svg { color: var(--faint); }
.net { display: block; width: 100%; height: 44px; margin-top: 8px; overflow: visible; }
.net path, .spark path { fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.net .rxl { stroke: var(--accent); stroke-width: 1.8; }
.net .txl { stroke: var(--faint); stroke-width: 1.3; stroke-dasharray: 3 3; }
.net .rxa { fill: url(#fade); stroke: none; }
/* ---------- the rack ---------- */
.rackhead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 18px 2px 8px; }
.rackhead h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.tally { display: flex; gap: 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.tally span { display: inline-flex; align-items: center; gap: 5px; }
.tally i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.rack { position: relative; background: var(--rack); border: 1px solid var(--rack-line); border-radius: 18px; padding: 10px 18px;
box-shadow: inset 0 2px 8px rgba(8,14,28,.07); }
.rack::before, .rack::after { content: ""; position: absolute; top: 12px; bottom: 12px; width: 8px; border-radius: 3px; background-color: var(--rail);
background-image: radial-gradient(circle at 50% 9px, var(--hole) 0 1.7px, transparent 2.2px); background-size: 8px 18px; }
.rack::before { left: 5px; } .rack::after { right: 5px; }
#units { display: flex; flex-direction: column; gap: 5px; }
.empty { padding: 26px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.hint { text-align: center; color: var(--faint); font-size: 11.5px; margin-top: 12px; }
.unit { position: relative; z-index: 1; border-radius: 11px; background: linear-gradient(180deg, var(--face), var(--face2)); border: 1px solid var(--line);
box-shadow: var(--shadow-face); --led: var(--ok);
transition: margin .38s cubic-bezier(.2,.9,.25,1), box-shadow .38s, transform .38s cubic-bezier(.2,.9,.25,1), border-color .3s; }
.unit.enter { animation: slot .5s cubic-bezier(.2,.8,.2,1) both; }
@keyframes slot { from { opacity: 0; transform: translateX(-14px) } }
.unit[data-state="restarting"] { --led: var(--warn); }
.unit[data-state="unhealthy"] { --led: var(--bad); border-color: var(--bad); }
.unit[data-state="stopped"] { --led: var(--off); }
.unit.open { z-index: 3; margin: 4px -11px; box-shadow: var(--shadow-pull); }
.face { display: flex; align-items: center; gap: 9px; width: 100%; height: 52px; padding: 0 12px 0 10px; border: 0; background: none; text-align: left; cursor: pointer; border-radius: 10px; }
.face:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.led { width: 20px; height: 20px; flex: none; overflow: visible; }
.led .halo { fill: var(--led); opacity: .2; transform-origin: 10px 10px; }
.led .core { fill: var(--led); filter: drop-shadow(0 0 calc(var(--led-glow) * 3px) var(--led)); }
.led .glint { fill: #fff; opacity: .55; }
.unit[data-state="running"] .halo { animation: breathe 3.2s ease-in-out infinite; }
.unit[data-state="running"] .core { animation: breathe-core 3.2s ease-in-out infinite; }
.unit[data-state="restarting"] .halo { animation: pulse .9s ease-out infinite; }
.unit[data-state="restarting"] .core { animation: blink .9s ease-in-out infinite; }
.unit[data-state="unhealthy"] .halo { opacity: .28; }
.unit[data-state="stopped"] .halo, .unit[data-state="stopped"] .glint { display: none; }
.unit[data-state="stopped"] .core { filter: none; }
@keyframes breathe { 0%, 100% { transform: scale(.7); opacity: .12 } 50% { transform: scale(1.05); opacity: .3 } }
@keyframes breathe-core { 0%, 100% { opacity: .78 } 50% { opacity: 1 } }
@keyframes pulse { from { transform: scale(.5); opacity: .55 } to { transform: scale(1.25); opacity: 0 } }
.who { flex: 1; min-width: 0; }
.who b { display: block; font-size: 14px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit[data-state="unhealthy"] .who span { color: var(--bad); }
.unit[data-state="restarting"] .who span { color: var(--warn); }
.unit[data-state="stopped"] .who b { color: var(--muted); }
.act { display: grid; grid-template-columns: repeat(3, 3px); gap: 3px; flex: none; }
.act i { width: 3px; height: 3px; border-radius: 50%; background: var(--track); transition: background .12s; }
.act i.on { background: var(--accent); box-shadow: 0 0 calc(var(--led-glow) * 4px) var(--accent); }
.spark { width: 64px; height: 24px; flex: none; overflow: visible; }
.spark .l { stroke: var(--accent); stroke-width: 1.5; }
.spark .a { fill: url(#fade); stroke: none; }
.unit[data-state="stopped"] .spark, .unit[data-state="stopped"] .act { opacity: .35; }
.pct { width: 36px; flex: none; text-align: right; font-size: 13px; font-weight: 650; }
.pct i { font-style: normal; font-size: 10.5px; color: var(--muted); font-weight: 600; margin-left: 1px; }
.drawer { display: grid; grid-template-rows: 0fr; visibility: hidden; transition: grid-template-rows .38s cubic-bezier(.2,.9,.25,1), visibility 0s .38s; }
.unit.open .drawer { grid-template-rows: 1fr; visibility: visible; transition-delay: 0s; }
.drawer > div { overflow: hidden; min-height: 0; }
.inner { margin: 0 12px; padding: 12px 0 12px; border-top: 1px solid var(--line2); }
.specs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 10px; }
.specs div { min-width: 0; }
.specs .wide { grid-column: 1 / -1; }
.specs dt { font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.specs dd { font-size: 13px; font-weight: 600; margin-top: 1px; overflow-wrap: anywhere; }
.specs dd.mono { font-family: var(--mono); font-size: 12px; font-weight: 500; }
.note { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; padding: 9px 11px; border-radius: 10px; font-size: 12.5px; line-height: 1.35;
background: var(--accent-soft); color: var(--text); }
.note[hidden] { display: none; }
.note svg { width: 15px; height: 15px; flex: none; margin-top: 1px; color: var(--accent); }
.note.err { background: rgba(226,61,79,.10); } .note.err svg { color: var(--bad); }
.btns { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 8px; border-radius: 10px; border: 1px solid var(--line);
background: transparent; font-size: 13px; font-weight: 650; cursor: pointer; white-space: nowrap; transition: opacity .2s, transform .12s, background .2s; }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.stop { color: var(--bad); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.busy svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }
.stale .card, .stale .rack { opacity: .55; transition: opacity .4s; }
.card, .rack { transition: opacity .4s; }
@media (min-width: 600px) {
.dial { width: 112px; height: 112px; }
.dial .read b { font-size: 28px; }
.card { padding: 22px; } .split { gap: 28px; }
.rack { padding: 14px 24px; } .rack::before { left: 8px; } .rack::after { right: 8px; }
.spark { width: 120px; } .face { gap: 14px; height: 58px; }
}
@media (max-width: 379px) { .face { gap: 7px; padding: 0 10px 0 8px; } .spark { width: 50px; } .pct { width: 34px; } .who b { font-size: 13.5px; } }
@media (max-width: 340px) { .act { display: none; } .loads { gap: 9px; } h1 { font-size: 22px; } }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation: none !important; transition: none !important; }
}
</style>
</head>
<body>
<svg class="defs" aria-hidden="true">
<defs>
<linearGradient id="fade" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color="var(--accent)" stop-opacity=".28"/>
<stop offset="1" stop-color="var(--accent)" stop-opacity="0"/>
</linearGradient>
</defs>
</svg>
<main id="app">
<div class="top">
<div class="brand">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true">
<rect x="2" y="2.5" width="12" height="4.5" rx="1.4"/><rect x="2" y="9" width="12" height="4.5" rx="1.4"/><path d="M4.6 4.75h.01M4.6 11.25h.01"/></svg>
Home lab
</div>
<div class="chips">
<span class="chip sim" id="sim" hidden>Simulated</span>
<span class="chip" id="link" role="status"><i></i><span id="linkText">Connecting</span></span>
</div>
</div>
<div class="hostrow">
<div style="min-width:0">
<h1 id="host"> </h1>
<div class="up">Up <b id="uptime">–</b></div>
</div>
<div class="loads" aria-label="Load averages">
<div><b id="l1">–</b><span>1 min</span></div>
<div><b id="l5">–</b><span>5 min</span></div>
<div><b id="l15">–</b><span>15 min</span></div>
</div>
</div>
<section class="card" aria-label="Host">
<div class="arcs">
<div class="arc none" id="aCpu"><div class="dial"><svg viewBox="0 0 88 88" aria-hidden="true"><circle class="t" cx="44" cy="44" r="36"/><circle class="v" cx="44" cy="44" r="36"/></svg>
<div class="read"><b>–</b><i>%</i></div></div><h2>CPU</h2><p> </p></div>
<div class="arc none" id="aMem"><div class="dial"><svg viewBox="0 0 88 88" aria-hidden="true"><circle class="t" cx="44" cy="44" r="36"/><circle class="v" cx="44" cy="44" r="36"/></svg>
<div class="read"><b>–</b><i>%</i></div></div><h2>Memory</h2><p> </p></div>
<div class="arc none" id="aTemp"><div class="dial"><svg viewBox="0 0 88 88" aria-hidden="true"><circle class="t" cx="44" cy="44" r="36"/><circle class="v" cx="44" cy="44" r="36"/></svg>
<div class="read"><b>–</b><i>°C</i></div></div><h2>Temp</h2><p> </p></div>
</div>
<div class="split">
<div>
<div class="label">Storage</div>
<div id="disks"></div>
</div>
<div>
<div class="label">Network</div>
<div class="rates">
<span class="rx"><svg viewBox="0 0 10 10" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 1v8M1.8 5.8 5 9l3.2-3.2"/></svg><span id="rx">–</span></span>
<span class="tx"><svg viewBox="0 0 10 10" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 9V1M1.8 4.2 5 1l3.2 3.2"/></svg><span id="tx">–</span></span>
</div>
<svg class="net" viewBox="0 0 100 48" preserveAspectRatio="none" aria-hidden="true"><path class="rxa" id="netA"/><path class="txl" id="netT"/><path class="rxl" id="netR"/></svg>
</div>
</div>
</section>
<div class="rackhead">
<h2>Rack</h2>
<div class="tally" id="tally"></div>
</div>
<section class="rack" aria-label="Services">
<div id="units"><div class="empty" id="empty">Looking for services…</div></div>
</section>
<p class="hint" id="hint" hidden>Tap a unit to pull it out</p>
</main>
<script>
(() => {
'use strict';
const $ = (id) => document.getElementById(id);
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
const num = (v, fallback = 0) => (typeof v === 'number' && isFinite(v) ? v : fallback);
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
const set = (el, text) => { if (el && el.textContent !== String(text)) el.textContent = text; };
const pad = (n) => String(n).padStart(2, '0');
function bytes(b, digits = 1) {
b = num(b);
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let i = 0;
while (b >= 1024 && i < units.length - 1) { b /= 1024; i++; }
return b.toFixed(i && b < 100 ? digits : 0) + ' ' + units[i];
}
function pair(used, total) {
// "2.6 / 3.6 TB": both in the unit of the total
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let i = 0, t = num(total), u = num(used);
while (t >= 1024 && i < units.length - 1) { t /= 1024; u /= 1024; i++; }
const d = t < 100 ? 1 : 0;
return u.toFixed(d) + ' / ' + t.toFixed(d) + ' ' + units[i];
}
function uptime(s) {
s = Math.max(0, Math.floor(num(s)));
const d = Math.floor(s / 86400), h = Math.floor(s / 3600) % 24, m = Math.floor(s / 60) % 60;
if (d) return d + 'd ' + h + 'h';
if (h) return h + 'h ' + pad(m) + 'm';
if (m) return m + 'm ' + pad(s % 60) + 's';
return s + 's';
}
/* A smooth line through the last values, newest at the right edge. */
function curve(values, slots, w, h, max, top = 2) {
if (values.length < 2) return '';
// Until the window is full, what there is spans the whole width.
const step = w / (Math.min(slots, values.length) - 1), usable = h - top - 1;
const pts = values.map((v, i) => [w - (values.length - 1 - i) * step, top + usable * (1 - clamp(v / max, 0, 1))]);
let d = 'M' + pts[0][0].toFixed(1) + ' ' + pts[0][1].toFixed(1);
for (let i = 1; i < pts.length; i++) {
const [x0, y0] = pts[i - 1], [x1, y1] = pts[i], mx = ((x0 + x1) / 2).toFixed(1);
d += 'C' + mx + ' ' + y0.toFixed(1) + ' ' + mx + ' ' + y1.toFixed(1) + ' ' + x1.toFixed(1) + ' ' + y1.toFixed(1);
}
return d;
}
const area = (d, w, h) => (d ? d + 'L' + w + ' ' + h + 'L0 ' + h + 'Z' : '');
/* ---------- the bar of the app follows light and dark ---------- */
const dark = matchMedia('(prefers-color-scheme: dark)');
function syncTheme() {
try {
window.connectivitizer?.setTheme?.(dark.matches ? { background: '#070b14', foreground: '#e8eefa' } : { background: '#f2f5fa', foreground: '#0e1a30' });
} catch (error) { /* a host without a bar */ }
}
syncTheme();
dark.addEventListener?.('change', syncTheme);
/* ---------- host ---------- */
const ARC = 2 * Math.PI * 36 * 0.75, FULL = 2 * Math.PI * 36;
document.querySelectorAll('.dial .t').forEach((c) => c.setAttribute('stroke-dasharray', ARC.toFixed(1) + ' ' + FULL.toFixed(1)));
document.querySelectorAll('.dial .v').forEach((c) => c.setAttribute('stroke-dasharray', '0 ' + FULL.toFixed(1)));
function arc(id, share, shown, sub, level) {
const el = $(id);
el.querySelector('.v').style.strokeDasharray = (share == null ? 0 : ARC * clamp(share, 0, 1)).toFixed(1) + ' ' + FULL.toFixed(1);
set(el.querySelector('.read b'), shown);
set(el.querySelector('p'), sub || ' ');
el.className = 'arc' + (level ? ' ' + level : '');
}
const level = (p, warn = 75, crit = 90) => (p >= crit ? 'crit' : p >= warn ? 'warn' : '');
const NET_SLOTS = 40;
const net = { rx: [], tx: [] };
let diskKey = null;
let topService = '';
function renderLoad(d) {
set($('host'), d.hostname || 'home lab');
set($('uptime'), uptime(d.uptimeSeconds));
$('sim').hidden = d.simulated !== true;
const load = Array.isArray(d.load) ? d.load : [];
['l1', 'l5', 'l15'].forEach((id, i) => set($(id), load[i] == null ? '–' : num(load[i]).toFixed(2)));
const cpu = clamp(num(d.cpuPercent), 0, 100);
arc('aCpu', cpu / 100, cpu.toFixed(0), topService ? 'top: ' + topService : '', level(cpu));
const mem = d.memory || {}, memP = mem.total ? (100 * num(mem.used)) / mem.total : 0;
arc('aMem', memP / 100, memP.toFixed(0), mem.total ? pair(mem.used, mem.total) : '', level(memP, 80, 92));
const t = d.temperatureC;
if (typeof t === 'number' && isFinite(t)) arc('aTemp', (t - 20) / 70, t.toFixed(0), t >= 85 ? 'too hot' : t >= 70 ? 'warm' : 'normal', level(t, 70, 85));
else arc('aTemp', null, '–', 'no sensor', 'none');
const disks = Array.isArray(d.disks) ? d.disks.slice(0, 4) : [];
const key = disks.map((x) => x.mount).join('\n');
const box = $('disks');
if (key !== diskKey) {
diskKey = key;
box.innerHTML = disks.map((x) => `<div class="disk"><div class="row"><b>${esc(x.mount)}</b><span></span></div><div class="bar"><i></i></div></div>`).join('')
|| '<div class="disk"><div class="row"><span>No disks reported</span></div></div>';
}
disks.forEach((x, i) => {
const row = box.children[i], p = x.total ? (100 * num(x.used)) / x.total : 0;
set(row.querySelector('span'), pair(x.used, x.total));
row.querySelector('.bar').className = 'bar ' + level(p, 80, 92);
row.querySelector('i').style.width = clamp(p, 0, 100).toFixed(1) + '%';
});
const n = d.network || {};
net.rx.push(num(n.rxBytesPerSec)); net.tx.push(num(n.txBytesPerSec));
while (net.rx.length > NET_SLOTS) { net.rx.shift(); net.tx.shift(); }
set($('rx'), bytes(n.rxBytesPerSec) + '/s'); set($('tx'), bytes(n.txBytesPerSec) + '/s');
const max = Math.max(16384, ...net.rx, ...net.tx) * 1.15;
const r = curve(net.rx, NET_SLOTS, 100, 48, max);
$('netR').setAttribute('d', r);
$('netA').setAttribute('d', area(r, 100, 48));
$('netT').setAttribute('d', curve(net.tx, NET_SLOTS, 100, 48, max));
}
/* ---------- rack ---------- */
const SPARK_SLOTS = 30, ACT = 6;
const STATES = ['unhealthy', 'restarting', 'running', 'stopped'];
const units = new Map(); // id -> { el, refs, cpu: [], data }
const pending = new Map(); // id -> the action on its way
const notes = new Map(); // id -> { kind, text }
let openId = null, firstPaint = true, epoch = 0;
const list = $('units');
const ICON = {
restart: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.2 8a5.2 5.2 0 1 1-1.6-3.75M13.3 2.4v2.9h-2.9"/></svg>',
stop: '<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><rect x="4" y="4" width="8" height="8" rx="1.6"/></svg>',
start: '<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M5.2 3.3v9.4a.6.6 0 0 0 .92.5l7.3-4.7a.6.6 0 0 0 0-1L6.12 2.8a.6.6 0 0 0-.92.5Z"/></svg>',
lock: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="7" width="10" height="6.5" rx="1.6"/><path d="M5.4 7V5.2a2.6 2.6 0 0 1 5.2 0V7"/></svg>',
alert: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="8" cy="8" r="6"/><path d="M8 4.8v3.6M8 11h.01"/></svg>',
};
const LABEL = { restart: 'Restart', stop: 'Stop', start: 'Start' };
function createUnit(id) {
const el = document.createElement('div');
el.className = 'unit';
el.dataset.id = id;
el.innerHTML = `
<button class="face" type="button" aria-expanded="false">
<svg class="led" viewBox="0 0 20 20" aria-hidden="true"><circle class="halo" cx="10" cy="10" r="9"/><circle class="core" cx="10" cy="10" r="4.4"/><circle class="glint" cx="8.6" cy="8.5" r="1.1"/></svg>
<span class="who"><b></b><span></span></span>
<span class="act" aria-hidden="true">${'<i></i>'.repeat(ACT)}</span>
<svg class="spark" viewBox="0 0 64 24" preserveAspectRatio="none" aria-hidden="true"><path class="a"/><path class="l"/></svg>
<span class="pct"></span>
</button>
<div class="drawer"><div><div class="inner">
<dl class="specs">
<div class="wide"><dt>Image</dt><dd class="mono" data-f="image"></dd></div>
<div><dt>Ports</dt><dd data-f="ports"></dd></div>
<div><dt>Memory</dt><dd data-f="memory"></dd></div>
<div><dt>Restarts</dt><dd data-f="restarts"></dd></div>
</dl>
<p class="note" hidden><span data-f="noteIcon"></span><span data-f="note"></span></p>
<div class="btns">
<button class="btn pri" type="button" data-act="restart">${ICON.restart}<span>Restart</span></button>
<button class="btn stop" type="button" data-act="stop">${ICON.stop}<span>Stop</span></button>
<button class="btn" type="button" data-act="start">${ICON.start}<span>Start</span></button>
</div>
</div></div></div>`;
const q = (selector) => el.querySelector(selector);
const refs = {
face: q('.face'), name: q('.who b'), sub: q('.who span'), dots: [...el.querySelectorAll('.act i')], line: q('.spark .l'), fill: q('.spark .a'), pct: q('.pct'),
image: q('[data-f=image]'), ports: q('[data-f=ports]'), memory: q('[data-f=memory]'), restarts: q('[data-f=restarts]'),
note: q('.note'), noteIcon: q('[data-f=noteIcon]'), noteText: q('[data-f=note]'),
buttons: { restart: q('[data-act=restart]'), stop: q('[data-act=stop]'), start: q('[data-act=start]') },
};
return { el, refs, cpu: [], data: null };
}
function paintUnit(unit, sample) {
const s = unit.data, r = unit.refs;
const state = STATES.includes(s.state) ? s.state : 'stopped';
const alive = state === 'running' || state === 'unhealthy';
const cpu = alive ? num(s.cpuPercent) : 0;
if (sample) { unit.cpu.push(cpu); while (unit.cpu.length > SPARK_SLOTS) unit.cpu.shift(); }
unit.el.dataset.state = state;
set(r.name, s.name || s.id);
set(r.sub, state === 'running' ? 'Up ' + uptime(s.uptimeSeconds) : state === 'unhealthy' ? 'Unhealthy · up ' + uptime(s.uptimeSeconds) : state === 'restarting' ? 'Restarting…' : 'Stopped');
if (alive) r.pct.innerHTML = (cpu < 10 ? cpu.toFixed(1) : cpu.toFixed(0)) + '<i>%</i>'; else set(r.pct, '–');
const max = Math.max(8, ...unit.cpu) * 1.2;
const d = curve(unit.cpu, SPARK_SLOTS, 64, 24, max);
r.line.setAttribute('d', d);
r.fill.setAttribute('d', area(d, 64, 24));
if (reduced || !alive) { const lit = alive ? Math.round(clamp(cpu / 60, 0, 1) * ACT) : 0; r.dots.forEach((dot, i) => dot.classList.toggle('on', i < lit)); }
set(r.image, s.image || '–');
const ports = Array.isArray(s.ports) ? s.ports : [];
set(r.ports, ports.length ? ports.join(', ') : 'none');
set(r.memory, alive ? bytes(s.memoryBytes) : '–');
set(r.restarts, num(s.restarts));
const busy = pending.get(s.id);
const can = { restart: alive, stop: alive, start: state === 'stopped' };
for (const action of ['restart', 'stop', 'start']) {
const button = r.buttons[action];
button.disabled = !!busy || !can[action];
button.classList.toggle('busy', busy === action || (action === 'restart' && state === 'restarting'));
}
const note = notes.get(s.id);
r.note.hidden = !note;
if (note) {
r.note.className = 'note' + (note.kind === 'err' ? ' err' : '');
const icon = note.kind === 'err' ? ICON.alert : ICON.lock;
if (r.noteIcon.dataset.k !== note.kind) { r.noteIcon.dataset.k = note.kind; r.noteIcon.innerHTML = icon; }
set(r.noteText, note.text);
}
const open = openId === s.id;
unit.el.classList.toggle('open', open);
r.face.setAttribute('aria-expanded', String(open));
r.face.setAttribute('aria-label', (s.name || s.id) + ', ' + state);
}
const rank = (s) => { const i = STATES.indexOf(s.state); return i < 0 ? STATES.length : i; };
function renderServices(services, sample) {
const seen = new Set();
services.forEach((s) => {
if (!s || s.id == null) return;
const id = String(s.id);
seen.add(id);
let unit = units.get(id);
if (!unit) { unit = createUnit(id); units.set(id, unit); }
unit.data = { ...s, id };
paintUnit(unit, sample);
});
for (const [id, unit] of units) if (!seen.has(id)) { unit.el.remove(); units.delete(id); pending.delete(id); notes.delete(id); if (openId === id) openId = null; }
const empty = $('empty');
if (empty) empty.hidden = units.size > 0;
if (empty && units.size === 0) empty.textContent = 'No services on this machine yet.';
$('hint').hidden = units.size === 0;
// Whatever needs attention comes first. While a unit is pulled out, nothing moves under the finger.
const current = [...list.querySelectorAll('.unit')].map((el) => el.dataset.id);
const wanted = [...units.values()].sort((a, b) => rank(a.data) - rank(b.data) || String(a.data.name).localeCompare(String(b.data.name))).map((u) => u.data.id);
const added = wanted.filter((id) => !current.includes(id));
if (added.length || (openId == null && wanted.join('\n') !== current.join('\n'))) {
const order = openId == null || firstPaint ? wanted : current.concat(added);
const before = new Map();
if (!reduced && !firstPaint) order.forEach((id) => before.set(id, units.get(id).el.getBoundingClientRect().top));
order.forEach((id, i) => {
const el = units.get(id).el;
if (!el.isConnected && !reduced) { el.classList.add('enter'); el.style.animationDelay = (firstPaint ? i * 45 : 0) + 'ms'; el.addEventListener('animationend', () => el.classList.remove('enter'), { once: true }); }
list.appendChild(el);
});
before.forEach((top, id) => {
const el = units.get(id).el, delta = top - el.getBoundingClientRect().top;
if (!delta || !el.animate) return;
el.animate([{ transform: 'translateY(' + delta + 'px)' }, { transform: 'none' }], { duration: 420, easing: 'cubic-bezier(.2,.8,.2,1)' });
});
firstPaint = false;
}
const count = { running: 0, restarting: 0, unhealthy: 0, stopped: 0 };
let top = null;
for (const unit of units.values()) {
const state = STATES.includes(unit.data.state) ? unit.data.state : 'stopped';
count[state]++;
if (state !== 'stopped' && (!top || num(unit.data.cpuPercent) > num(top.cpuPercent))) top = unit.data;
}
topService = top ? String(top.name || top.id) : '';
const tally = [['running', 'var(--ok)'], ['unhealthy', 'var(--bad)'], ['restarting', 'var(--warn)'], ['stopped', 'var(--off)']]
.filter(([state]) => count[state] > 0).map(([state, colour]) => `<span><i style="--c:${colour}"></i>${count[state]} ${state}</span>`).join('');
if ($('tally').dataset.k !== tally) { $('tally').dataset.k = tally; $('tally').innerHTML = tally; }
}
/* Activity lights: the busier a service, the more of them are lit at any moment. */
if (!reduced) {
setInterval(() => {
for (const unit of units.values()) {
const s = unit.data;
if (!s || (s.state !== 'running' && s.state !== 'unhealthy')) continue;
const chance = 0.05 + clamp(num(s.cpuPercent) / 45, 0, 1) * 0.8;
unit.refs.dots.forEach((dot) => dot.classList.toggle('on', Math.random() < chance));
}
}, 150);
}
list.addEventListener('click', (event) => {
const el = event.target.closest('.unit');
if (!el) return;
const id = el.dataset.id, button = event.target.closest('[data-act]');
if (button) { if (!button.disabled) act(id, button.dataset.act); return; }
if (!event.target.closest('.face')) return;
const previous = openId;
openId = previous === id ? null : id;
notes.delete(id);
for (const other of [previous, id]) { const unit = units.get(other); if (unit) paintUnit(unit, false); }
if (openId == null) renderServices([...units.values()].map((u) => u.data), false);
});
async function act(id, action) {
if (pending.has(id)) return;
pending.set(id, action);
notes.delete(id);
paintUnit(units.get(id), false);
let note = null, answer = null;
try {
const response = await fetch('/services/' + encodeURIComponent(id) + '/' + action, { method: 'POST' });
if (response.status === 403) note = { kind: 'ro', text: 'Read-only mode: this panel is only watching. Start the program with --allow-actions to ' + action + ' services from here.' };
else if (response.status === 404) note = { kind: 'err', text: 'This service is no longer there.' };
else if (!response.ok) note = { kind: 'err', text: LABEL[action] + ' did not work (' + response.status + '). Try again in a moment.' };
else answer = await response.json().catch(() => null);
} catch (error) {
note = { kind: 'err', text: 'The device did not answer. Try again in a moment.' };
}
pending.delete(id);
epoch++;
const unit = units.get(id);
if (!unit) return;
if (note) notes.set(id, note);
if (answer && typeof answer === 'object' && answer.state) unit.data = { ...unit.data, ...answer, id };
renderServices([...units.values()].map((u) => u.data), false);
}
/* ---------- polling ---------- */
const POLL_MS = 1500, TIMEOUT_MS = 6000;
let everLoaded = false, failures = 0;
function get(path) {
return Promise.race([
fetch(path).then((response) => { if (!response.ok) throw new Error(path + ' answered ' + response.status); return response.json(); }),
new Promise((resolve, reject) => setTimeout(() => reject(new Error(path + ' took too long')), TIMEOUT_MS)),
]);
}
function link(state) {
const chip = $('link');
chip.className = 'chip' + (state === 'live' ? ' live' : state === 'down' ? ' down' : '');
set($('linkText'), state === 'live' ? 'Live' : state === 'down' ? 'Offline, retrying' : 'Connecting');
$('app').classList.toggle('stale', state === 'down');
}
async function poll() {
const started = epoch;
try {
const [load, services] = await Promise.all([get('/load'), get('/services')]);
if (!load || typeof load !== 'object' || !Array.isArray(services)) throw new Error('unexpected answer');
// An answer that was asked for before an action finished would show the state from before it.
if (started === epoch) renderServices(services, true);
renderLoad(load);
everLoaded = true; failures = 0;
link('live');
} catch (error) {
failures++;
link('down');
if (!everLoaded) { const empty = $('empty'); if (empty) empty.textContent = 'Cannot reach the device. Trying again…'; }
}
setTimeout(poll, POLL_MS);
}
poll();
})();
</script>
</body>
</html>