Show occupied disk and RAM capacity with matching used and free segments
Rust development slice / linux (push) Failing after 9s

This commit is contained in:
2026-11-20 08:40:48 +01:00
parent 957bf3cd58
commit b5e96853c3
5 changed files with 44 additions and 39 deletions
+23 -22
View File
@@ -44,9 +44,13 @@ function gib(v: unknown) {
return typeof v === 'number' && Number.isFinite(v) && v >= 0 ? number.format(v / 2 ** 30) : null;
}
function capacity(free: unknown, total: unknown) {
const f = gib(free),
t = gib(total);
return f === null && t === null ? unknown : `${f ?? '–'} / ${t ?? '–'} GiB`;
if (typeof total !== 'number' || !Number.isFinite(total) || total <= 0)
return { text: unknown, usedPercent: null };
const used = typeof free === 'number' && free >= 0 && free <= total ? total - free : null;
return {
text: `${gib(used) ?? '–'} / ${gib(total)} GiB`,
usedPercent: used === null ? null : (used / total) * 100
};
}
function cpuUsage(value: unknown) {
return typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100
@@ -94,24 +98,21 @@ function Capacity({ free, total }: {
free: unknown;
total: unknown;
}) {
const freePercent = typeof free === 'number' && typeof total === 'number' &&
Number.isFinite(total) && free >= 0 && free <= total && total > 0
? (free / total) * 100
: null;
const displayFree = freePercent === null ? null : Math.round(freePercent * 10) / 10;
const freeLabel = displayFree === null ? '' : `${number.format(displayFree)} % frei`;
const breakdown = displayFree === null ? '' : `${freeLabel}, ${number.format(100 - displayFree)} % belegt`;
const { text, usedPercent } = capacity(free, total);
const displayUsed = usedPercent === null ? null : Math.round(usedPercent * 10) / 10;
const usedLabel = displayUsed === null ? '' : `${number.format(displayUsed)} % belegt`;
const breakdown = displayUsed === null ? '' : `${usedLabel}, ${number.format(100 - displayUsed)} % frei`;
return (
<>
<span>{capacity(free, total)}</span>
{freePercent !== null && (
<span>{text}</span>
{usedPercent !== null && (
<>
<span className="capacity-track" role="img"
aria-label={breakdown} title={breakdown}>
<span className="capacity-free" style={{ width: `${freePercent}%` }} />
<span className="capacity-used" />
<span className="capacity-used" style={{ width: `${usedPercent}%` }} />
<span className="capacity-free" />
</span>
<small className="capacity-caption" aria-hidden="true">{freeLabel}</small>
<small className="capacity-caption" aria-hidden="true">{usedLabel}</small>
</>
)}
</>
@@ -252,10 +253,10 @@ function DeviceDetail({
['Type', label(d.device_type)],
['Betriebssystem', label(d.os)],
...systemDetails(d, time),
['RAM frei / gesamt', capacity(d.ram_available_bytes, d.ram_total_bytes)],
['RAM belegt / gesamt', capacity(d.ram_available_bytes, d.ram_total_bytes).text],
['CPU', [cpu(d).primary, cpu(d).secondary].filter(Boolean).join(' · ')],
['CPU-Auslastung', [cpuUsage(d.cpu_usage_percent), measuredAt(d.cpu_usage_observed_at)].filter(Boolean).join(' · ')],
['Speicher frei / gesamt', capacity(d.disk_free_bytes, d.disk_total_bytes)],
['Speicher belegt / gesamt', capacity(d.disk_free_bytes, d.disk_total_bytes).text],
['Letzter Kontakt', time(d.last_contact_at)],
['Inventar erhoben', time(d.observed_at)],
['Agentversion', label(d.agent_version)],
@@ -306,14 +307,14 @@ function DeviceDetail({
<thead>
<tr>
<th>Laufwerk</th>
<th>Speicher frei / gesamt</th>
<th>Speicher belegt / gesamt</th>
</tr>
</thead>
<tbody>
{volumes.map((v, i) => (
<tr key={i}>
<td>{label(v.name)}</td>
<td>{capacity(v.free_bytes, v.total_bytes)}</td>
<td>{capacity(v.free_bytes, v.total_bytes).text}</td>
</tr>
))}
</tbody>
@@ -633,7 +634,7 @@ export function Devices({
<span className="sr-only">Ziel auswählen</span>
</th>
)}
{['Hostname', 'Type', 'Zweck', 'OS', 'Status', 'Speicher frei / gesamt', 'RAM frei / gesamt', 'CPU', 'Kunde'].map(
{['Hostname', 'Type', 'Zweck', 'OS', 'Status', 'Speicher belegt / gesamt', 'RAM belegt / gesamt', 'CPU', 'Kunde'].map(
(h) => (
<th scope="col" key={h} className={h === 'Zweck' ? 'purpose-col' : undefined}>
{h}
@@ -697,10 +698,10 @@ export function Devices({
<small>Zuletzt {time(d.last_contact_at)}</small>
)}
</td>
<td data-label="Speicher frei / gesamt" className="capacity-cell">
<td data-label="Speicher belegt / gesamt" className="capacity-cell">
<Capacity free={d.disk_free_bytes} total={d.disk_total_bytes} />
</td>
<td data-label="RAM frei / gesamt" className="capacity-cell" title={measuredAt(d.ram_observed_at)}>
<td data-label="RAM belegt / gesamt" className="capacity-cell" title={measuredAt(d.ram_observed_at)}>
<Capacity free={d.ram_available_bytes} total={d.ram_total_bytes} />
</td>
<td data-label="CPU">
+2 -2
View File
@@ -106,8 +106,8 @@ section.fleet { padding:0; overflow:hidden; }
.host-link { padding:0; background:none; color:var(--accent); text-align:left; font-weight:680; margin:0; overflow-wrap:anywhere; }
.fleet-table .capacity-cell { font-variant-numeric:tabular-nums; }
.capacity-track { display:flex; width:min(90px,100%); border-radius:2px; background:#e1ebe6; height:6px; margin-top:6px; overflow:hidden; }
.capacity-free { flex:none; background:#c78980; }
.capacity-used { flex:1; background:#2e7657; }
.capacity-used { flex:none; background:#c78980; }
.capacity-free { flex:1; background:#2e7657; }
.capacity-caption { display:block; color:var(--subtle); }
.presence { display:inline-flex; align-items:center; gap:5px; border-radius:20px; padding:2px 8px; background:#edf1ef; color:#4d5f59; font-size:.8rem; font-weight:650; }
.presence i { width:6px; height:6px; border-radius:50%; background:currentColor; }