Show disk, pool and unassigned Linux capacity in device fleet views

This commit is contained in:
2026-11-20 09:35:05 +01:00
parent eaaa6ff228
commit 79f236b3ea
4 changed files with 53 additions and 1 deletions
+7
View File
@@ -562,6 +562,13 @@ fn project(row: &PgRow, now: DateTime<Utc>, full: bool, hosts: &HashMap<Uuid, Ho
if full || observed(&data, "windows.volumes").is_object() { if full || observed(&data, "windows.volumes").is_object() {
item["volumes"] = volumes(&data); item["volumes"] = volumes(&data);
} }
if let Some(scope) = data["observations"].as_array().and_then(|scopes|
scopes.iter().find(|s| s["scope"] == "linux.disks")) {
item["disks"] = if scope["quality"] == "valid" && scope["data"].is_array() {
scope["data"].clone()
} else { Value::Null };
item["disks_truncated"] = json!(scope["truncated"] == true);
}
if device_type == Some(DeviceType::Virtual) && row.get::<String, _>("lifecycle") == "current" { if device_type == Some(DeviceType::Virtual) && row.get::<String, _>("lifecycle") == "current" {
let assigned_id: Option<Uuid> = row.get("hypervisor_asset_id"); let assigned_id: Option<Uuid> = row.get("hypervisor_asset_id");
let assigned = assigned_id.and_then(|id| hosts.get(&id)); let assigned = assigned_id.and_then(|id| hosts.get(&id));
+14
View File
@@ -30,6 +30,7 @@ test('shows used disk and RAM in GiB and draws the occupied share in red on desk
['missing-available', null, 16 * gib], ['missing-available', null, 16 * gib],
['invalid-range', 17 * gib, 16 * gib], ['invalid-range', 17 * gib, 16 * gib],
['invalid-total', 0, 0], ['invalid-total', 0, 0],
['linux-drives', null, null],
] as const; ] as const;
const listing = (items: unknown[]) => ({ const listing = (items: unknown[]) => ({
items, next_cursor: null, truncated: false, completeness: 'complete', as_of: '2026-11-19T12:00:00Z' items, next_cursor: null, truncated: false, completeness: 'complete', as_of: '2026-11-19T12:00:00Z'
@@ -49,6 +50,11 @@ test('shows used disk and RAM in GiB and draws the occupied share in red on desk
tenant_id: customer.tenant_id, customer_name: customer.name, asset_id: hostname, agent_id: hostname, tenant_id: customer.tenant_id, customer_name: customer.name, asset_id: hostname, agent_id: hostname,
lifecycle: 'current', status: 'online', hostname, ram_available_bytes: free, ram_total_bytes: total, lifecycle: 'current', status: 'online', hostname, ram_available_bytes: free, ram_total_bytes: total,
disk_free_bytes: free, disk_total_bytes: total, disk_free_bytes: free, disk_total_bytes: total,
...(hostname === 'linux-drives' ? {disks:[
{kind:'disk',name:'sda',model:'Testplatte',total_bytes:64*gib,used_bytes:16*gib,available_bytes:40*gib},
{kind:'disk',name:'sdb',total_bytes:64*gib,used_bytes:null,available_bytes:null},
{kind:'group',name:'md0',members:['sda','sdb'],total_bytes:8*gib,used_bytes:2*gib,available_bytes:6*gib}
]} : {}),
...(hostname === 'mostly-free' ? { volumes: [ ...(hostname === 'mostly-free' ? { volumes: [
{ name: 'C:', free_bytes: free, total_bytes: total }, { name: 'C:', free_bytes: free, total_bytes: total },
{ name: 'D:', free_bytes: 0, total_bytes: 64 * gib }, { name: 'D:', free_bytes: 0, total_bytes: 64 * gib },
@@ -92,6 +98,14 @@ test('shows used disk and RAM in GiB and draws the occupied share in red on desk
await expect(drives.nth(1).getByRole('img', { name: '100 % belegt, 0 % frei' })).toBeVisible(); await expect(drives.nth(1).getByRole('img', { name: '100 % belegt, 0 % frei' })).toBeVisible();
await expect(drives.nth(2)).toHaveText('E: Nicht gemeldet'); await expect(drives.nth(2)).toHaveText('E: Nicht gemeldet');
await expect(drives.nth(2).getByRole('img')).toHaveCount(0); await expect(drives.nth(2).getByRole('img')).toHaveCount(0);
const linux = row('linux-drives').locator('.drive-capacity');
await expect(linux).toHaveCount(3);
await expect(linux.nth(0)).toContainText('16 / 64 GiB');
await expect(linux.nth(0).getByRole('img',{name:'25 % belegt, 62,5 % frei, 12,5 % nicht zugeordnet'})).toBeVisible();
await expect(linux.nth(1)).toContainText('Belegung nicht ermittelbar');
await expect(linux.nth(1)).toContainText('Im Verbund: md0');
await expect(linux.nth(2)).toContainText('Verbund: md0');
await expect(linux.nth(2)).toContainText('2 / 8 GiB');
} }
}); });
+30 -1
View File
@@ -119,12 +119,41 @@ function Capacity({ free, total }: {
); );
} }
function LinuxDisk({ disk, groups }: { disk: RecordValue; groups: string[] }) {
const { used_bytes: used, available_bytes: free, total_bytes: total } = disk;
const size = typeof total === 'number' && Number.isFinite(total) && total > 0 ? total : null;
const valid = size !== null && typeof used === 'number' && used >= 0 && typeof free === 'number' && free >= 0 && used + free <= size;
const usedPct = valid ? used / size * 100 : 0, freePct = valid ? free / size * 100 : 0;
const summary = valid ? `${number.format(usedPct)} % belegt, ${number.format(freePct)} % frei, ${number.format(Math.max(0,100-usedPct-freePct))} % nicht zugeordnet` : 'Belegung nicht ermittelbar';
const group = disk.kind === 'group';
return <div className="drive-capacity">
<strong>{group ? 'Verbund: ' : ''}{label(disk.name)}</strong>
{typeof disk.model === 'string' && <small>{disk.model}</small>}
{group && Array.isArray(disk.members) && disk.members.length > 0 && <small>{disk.members.filter(v => typeof v === 'string').join(', ')}</small>}
{!group && groups.length > 0 && <small>Im Verbund: {groups.join(', ')}</small>}
<div>{size === null ? 'Größe nicht gemeldet' : `${valid ? gib(used) : '–'} / ${gib(size)} GiB`}</div>
{size !== null && <span className="capacity-track disk-track" role="img" aria-label={summary} title={summary}>
<span className="capacity-used" style={{width:`${usedPct}%`}} />
<span className="capacity-free" style={{width:`${freePct}%`}} />
</span>}
<small>{valid ? `${number.format(usedPct)} % belegt` : summary}</small>
</div>;
}
function DiskCapacity({ device }: { device: RecordValue }) { function DiskCapacity({ device }: { device: RecordValue }) {
if ('disks' in device) {
const disks = Array.isArray(device.disks) ? device.disks.filter(d => d && typeof d === 'object' && ['disk','group'].includes(d.kind) && typeof d.name === 'string') : [];
return <>{disks.length ? disks.map((disk,i) => <LinuxDisk key={`${disk.kind}/${disk.name}/${i}`} disk={disk}
groups={disk.kind === 'disk' ? disks.filter(g => g.kind === 'group' && Array.isArray(g.members) && g.members.includes(disk.name)).map(g => g.name) : []}/>) :
<small>Keine Festplatten gemeldet</small>}
{device.disks_truncated === true && <small>Liste gekürzt</small>}</>;
}
// Only Windows fleet rows use drive letters. Linux mount inventories remain // Only Windows fleet rows use drive letters. Linux mount inventories remain
// available in the detail view, without expanding every fleet row. // available in the detail view, without expanding every fleet row.
const drives = Array.isArray(device.volumes) const drives = Array.isArray(device.volumes)
? device.volumes.map(v => record(v)).filter(v => typeof v.name === 'string' && /^[A-Z]:$/.test(v.name)) : []; ? device.volumes.map(v => record(v)).filter(v => typeof v.name === 'string' && /^[A-Z]:$/.test(v.name)) : [];
if (!drives.length) return <Capacity free={device.disk_free_bytes} total={device.disk_total_bytes} />; if (!drives.length) return <>{device.source_id === 'linux.base' && <small>Root-Dateisystem /</small>}
<Capacity free={device.disk_free_bytes} total={device.disk_total_bytes} /></>;
return <>{drives.map(drive => ( return <>{drives.map(drive => (
<div className="drive-capacity" key={String(drive.name)}> <div className="drive-capacity" key={String(drive.name)}>
<strong>{String(drive.name)}</strong>{' '}<Capacity free={drive.free_bytes} total={drive.total_bytes} /> <strong>{String(drive.name)}</strong>{' '}<Capacity free={drive.free_bytes} total={drive.total_bytes} />
+2
View File
@@ -109,6 +109,8 @@ section.fleet { padding:0; overflow:hidden; }
.capacity-track { display:flex; width:min(90px,100%); border-radius:2px; background:#e1ebe6; height:6px; margin-top:6px; overflow:hidden; } .capacity-track { display:flex; width:min(90px,100%); border-radius:2px; background:#e1ebe6; height:6px; margin-top:6px; overflow:hidden; }
.capacity-used { flex:none; background:#c78980; } .capacity-used { flex:none; background:#c78980; }
.capacity-free { flex:1; background:#2e7657; } .capacity-free { flex:1; background:#2e7657; }
.disk-track { background:#aebbb6; }
.disk-track .capacity-free { flex:none; }
.capacity-caption { display:block; color:var(--subtle); } .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 { 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; } .presence i { width:6px; height:6px; border-radius:50%; background:currentColor; }