mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
Warn in the navbar when a hard drive runs hot (#470)
* Warn in the navbar when a hard drive runs hot. The navbar already warns about high CPU temperature; add the equivalent for drive temperature, since an overheating disk risks data loss and a user running an off-grid library won't be watching for it. - controller/lib/smart.py: build_smart_stats() returns the per-drive list plus warning thresholds (55C warn / 65C critical) so the frontend stays dumb. Reading SMART wakes a spun-down drive, so drives in standby are detected with `smartctl -n standby` (which works through the USB-SATA bridges where `hdparm -C` only reports "unknown") and NOT read; their last-known reading is reused instead. - controller/lib/status_worker.py: collect SMART on a slow 60s cadence (cached on app.state) rather than the 5s status loop, so the poll does not keep USB drives awake. The result flows into the same cached payload via a new collect_all_status(smart_stats=...) kwarg. - Frontend: useDriveTemperature() reports the hottest drive; Nav.js shows a yellow/red `hdd` icon with a popup, mirroring the CPU warning. Verified on hardware: smart_stats reports real temps and SMART runs once a minute, not every 5s. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Address Greptile review on HDD temperature warning. - _drive_is_asleep also treats SLEEP mode as asleep, not just STANDBY. smartctl -n standby exits "Device is in SLEEP mode, exit(2)" for the deeper power mode; matching only "STANDBY" meant a SLEEP drive was read and woken — the exact failure the check prevents. (TDD: added a failing SLEEP test, then fixed.) - useDriveTemperature uses ?? instead of || for the temperature fallback to express "fall back only on null/undefined". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b112f07b4a
commit
51f89593a4
8 changed files with 450 additions and 8 deletions
|
|
@ -4,7 +4,15 @@ import {Dropdown, Icon as SIcon, Menu} from "semantic-ui-react";
|
|||
import {Media, SettingsContext, StatusContext, ThemeContext} from "../contexts/contexts";
|
||||
import {DarkModeToggle, HotspotStatusIcon, useLocalStorage} from "./Common";
|
||||
import {ShareButton} from "./Share";
|
||||
import {useCPUTemperature, useIOStats, useLoad, useMemoryStats, usePowerStats, useWROLMode} from "../hooks/customHooks";
|
||||
import {
|
||||
useCPUTemperature,
|
||||
useDriveTemperature,
|
||||
useIOStats,
|
||||
useLoad,
|
||||
useMemoryStats,
|
||||
usePowerStats,
|
||||
useWROLMode
|
||||
} from "../hooks/customHooks";
|
||||
import {useReorganizationStatus} from "../contexts/FileWorkerStatusContext";
|
||||
import {SearchIconButton} from "./Search";
|
||||
import {Icon, Popup} from "./Theme";
|
||||
|
|
@ -174,6 +182,21 @@ export function NavBar() {
|
|||
temperatureIcon = <Popup content={`CPU: ${temperature.toFixed()}°C`} trigger={link}/>;
|
||||
}
|
||||
|
||||
// Hard-drive temperature. An overheating drive risks data loss.
|
||||
const {
|
||||
device: hotDrive,
|
||||
temperature: driveTemperature,
|
||||
highTemperature: driveHighTemperature,
|
||||
criticalTemperature: driveCriticalTemperature,
|
||||
} = useDriveTemperature();
|
||||
let driveTemperatureIcon;
|
||||
if (driveTemperature && driveTemperature >= driveHighTemperature) {
|
||||
const color = driveTemperature >= driveCriticalTemperature ? highWarningColor : lowWarningColor;
|
||||
const icon = <Icon data-testid='driveTemperatureIcon' name='hdd' size='large' color={color}/>
|
||||
const link = <Link to='/admin/status'>{icon}</Link>;
|
||||
driveTemperatureIcon = <Popup content={`${hotDrive}: ${driveTemperature.toFixed()}°C`} trigger={link}/>;
|
||||
}
|
||||
|
||||
// Power issues, this is always displayed if detected.
|
||||
const {underVoltage, overCurrent} = usePowerStats();
|
||||
let powerIcon;
|
||||
|
|
@ -189,7 +212,7 @@ export function NavBar() {
|
|||
// Display the temperature icon first because it can cause the system to throttle. The rest are in order of effects
|
||||
// that will slow down the system and the user should address. Generic load is last because it is probably not an
|
||||
// issue.
|
||||
const warningIcon = temperatureIcon || diskWaitIcon || memoryIcon || systemLoadIcon;
|
||||
const warningIcon = temperatureIcon || driveTemperatureIcon || diskWaitIcon || memoryIcon || systemLoadIcon;
|
||||
|
||||
const {isReorganizing, taskType, collectionId, collectionKind} = useReorganizationStatus();
|
||||
|
||||
|
|
|
|||
|
|
@ -1335,6 +1335,28 @@ export const useCPUTemperature = () => {
|
|||
return {temperature, highTemperature, criticalTemperature}
|
||||
}
|
||||
|
||||
// Reports the hottest drive's SMART temperature so the navbar can warn about
|
||||
// an overheating disk, mirroring useCPUTemperature. Drives without a
|
||||
// temperature reading (USB flash, unsupported bridges, spun-down) are ignored.
|
||||
export const useDriveTemperature = () => {
|
||||
const {status} = React.useContext(StatusContext);
|
||||
const smart = status?.smart_stats;
|
||||
const highTemperature = smart?.high_temperature || 55;
|
||||
const criticalTemperature = smart?.critical_temperature || 65;
|
||||
|
||||
const drives = Array.isArray(smart?.drives) ? smart.drives : [];
|
||||
const hottest = drives
|
||||
.filter((d) => typeof d.temperature === 'number')
|
||||
.reduce((max, d) => (max === null || d.temperature > max.temperature ? d : max), null);
|
||||
|
||||
return {
|
||||
device: hottest?.device || null,
|
||||
temperature: hottest?.temperature ?? 0,
|
||||
highTemperature,
|
||||
criticalTemperature,
|
||||
}
|
||||
}
|
||||
|
||||
export const useLoad = () => {
|
||||
const {status} = React.useContext(StatusContext);
|
||||
let minute_1 = status?.load_stats?.minute_1;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import React from 'react';
|
||||
import {act, renderHook} from '@testing-library/react';
|
||||
import {render, screen} from '@testing-library/react';
|
||||
import {usePages} from './customHooks';
|
||||
import {QueryContext} from '../contexts/contexts';
|
||||
import {usePages, useDriveTemperature} from './customHooks';
|
||||
import {QueryContext, StatusContext} from '../contexts/contexts';
|
||||
import {Paginator} from '../components/Common';
|
||||
|
||||
// Build a wrapper that provides a controlled QueryContext so usePages can read
|
||||
|
|
@ -95,6 +95,73 @@ describe('usePages.setTotal -> totalPages', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('useDriveTemperature', () => {
|
||||
const makeStatusWrapper = (status) => ({children}) => (
|
||||
<StatusContext.Provider value={{status}}>
|
||||
{children}
|
||||
</StatusContext.Provider>
|
||||
);
|
||||
|
||||
test('selects the hottest drive and reads thresholds from the payload', () => {
|
||||
const status = {
|
||||
smart_stats: {
|
||||
drives: [
|
||||
{device: 'sda', temperature: 51},
|
||||
{device: 'sdb', temperature: 60},
|
||||
],
|
||||
high_temperature: 55,
|
||||
critical_temperature: 65,
|
||||
},
|
||||
};
|
||||
const {result} = renderHook(() => useDriveTemperature(),
|
||||
{wrapper: makeStatusWrapper(status)});
|
||||
expect(result.current.device).toBe('sdb');
|
||||
expect(result.current.temperature).toBe(60);
|
||||
expect(result.current.highTemperature).toBe(55);
|
||||
expect(result.current.criticalTemperature).toBe(65);
|
||||
});
|
||||
|
||||
test('ignores drives without a numeric temperature', () => {
|
||||
const status = {
|
||||
smart_stats: {
|
||||
drives: [
|
||||
{device: 'sda', temperature: null},
|
||||
{device: 'sdb', temperature: 48},
|
||||
],
|
||||
high_temperature: 55,
|
||||
critical_temperature: 65,
|
||||
},
|
||||
};
|
||||
const {result} = renderHook(() => useDriveTemperature(),
|
||||
{wrapper: makeStatusWrapper(status)});
|
||||
expect(result.current.device).toBe('sdb');
|
||||
expect(result.current.temperature).toBe(48);
|
||||
});
|
||||
|
||||
test('defaults to no warning and default thresholds when smart_stats is absent', () => {
|
||||
const {result} = renderHook(() => useDriveTemperature(),
|
||||
{wrapper: makeStatusWrapper({})});
|
||||
expect(result.current.device).toBeNull();
|
||||
expect(result.current.temperature).toBe(0);
|
||||
expect(result.current.highTemperature).toBe(55);
|
||||
expect(result.current.criticalTemperature).toBe(65);
|
||||
});
|
||||
|
||||
test('returns no drive when none report a temperature', () => {
|
||||
const status = {
|
||||
smart_stats: {
|
||||
drives: [{device: 'sda', temperature: null}],
|
||||
high_temperature: 55,
|
||||
critical_temperature: 65,
|
||||
},
|
||||
};
|
||||
const {result} = renderHook(() => useDriveTemperature(),
|
||||
{wrapper: makeStatusWrapper(status)});
|
||||
expect(result.current.device).toBeNull();
|
||||
expect(result.current.temperature).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Paginator rendering', () => {
|
||||
test('renders exactly totalPages numbered page links (no phantom trailing link)', () => {
|
||||
// 48 results at 24 per page -> 2 pages. If totalPages is 3, semantic-ui
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue