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>
This commit is contained in:
25
frontend/src/lib/admin/temps.ts
Normal file
25
frontend/src/lib/admin/temps.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
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));
|
||||
}
|
||||
Reference in New Issue
Block a user