Files
Mangalord/frontend/src/lib/admin/temps.ts
MechaCat02 d64ab038ef
Some checks failed
deploy / test-frontend (pull_request) Waiting to run
deploy / build-and-push (pull_request) Blocked by required conditions
deploy / deploy (pull_request) Blocked by required conditions
deploy / test-backend (pull_request) Has been cancelled
refactor(admin): focus System tab temperatures on the CPU die
The Temperatures box listed every component sysinfo exposes (per-core,
chipset, NVMe…), dominating the System tab. Surface only the CPU
die/package reading and collapse the rest behind a disclosure.

Add a tested pure helper, pickCpuTemp, that selects the best CPU sensor
(Intel package → AMD Tctl/Tdie → hottest core → any cpu/coretemp → null),
and render it via a shared Temp snippet with the remaining sensors in a
default-closed "N other sensors" details element.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 20:19:14 +02:00

26 lines
1.1 KiB
TypeScript

import type { TempStat } from '$lib/api/admin';
/** Pick the sensor that best represents the CPU die/package temperature
* from a heterogeneous component list. Intel exposes
* `coretemp Package id 0`; AMD exposes `k10temp Tctl`/`Tdie`. When neither
* is present we fall back to the hottest individual core, then to any
* CPU-ish sensor, and finally `null` (nothing CPU-related — e.g. only NVMe
* / chipset sensors are exposed). Used to keep the System tab focused on
* the one reading operators care about, with the rest tucked away. */
export function pickCpuTemp(temps: TempStat[]): TempStat | null {
const byLabel = (re: RegExp) => temps.find((t) => re.test(t.label)) ?? null;
return (
byLabel(/package/i) ??
byLabel(/tctl|tdie|k10temp/i) ??
hottestCore(temps) ??
byLabel(/cpu|coretemp/i) ??
null
);
}
function hottestCore(temps: TempStat[]): TempStat | null {
const cores = temps.filter((t) => /core\s*\d+/i.test(t.label));
if (cores.length === 0) return null;
return cores.reduce((a, b) => (b.celsius > a.celsius ? b : a));
}