Using iostat to detect busy disk issues, reporting them in the UI. Detecting under-voltage/over-current issues using dmesg and reporting them in the UI.

This commit is contained in:
Roland 2025-01-10 11:33:21 -07:00
parent 220cb8010f
commit d8b3db9d63
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
14 changed files with 339 additions and 282 deletions

View file

@ -20,15 +20,7 @@ import {
} from 'semantic-ui-react';
import {Link, NavLink, useNavigate, useSearchParams} from "react-router-dom";
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
import {
useCPUTemperature,
useHotspot,
useLoad,
useSearchDirectories,
useSearchOrder,
useThrottle,
useWROLMode
} from "../hooks/customHooks";
import {useHotspot, useSearchDirectories, useSearchOrder, useThrottle, useWROLMode} from "../hooks/customHooks";
import {Media, SettingsContext, StatusContext, ThemeContext} from "../contexts/contexts";
import {
Accordion,
@ -1124,38 +1116,6 @@ export function HotspotStatusIcon() {
</>
}
export function CPUTemperatureIcon({size = 'large', fallback = null}) {
// Returns an Icon only if temperature is too high.
const {temperature, highTemperature, criticalTemperature} = useCPUTemperature();
if (temperature === null || temperature < highTemperature) {
// Temperature is not a problem.
return fallback;
}
let icon = temperature >= criticalTemperature ?
<Icon data-testid='cpuTemperatureIcon' name='thermometer' size={size} color='red'/>
: <Icon data-testid='cpuTemperatureIcon' name='thermometer half' size={size} color='yellow'/>;
icon = <Link to='/admin/status'>{icon}</Link>;
return <Popup content={`CPU: ${temperature}°C`} trigger={icon}/>
}
export function SystemLoadIcon({size = 'large', fallback = null}) {
const {minute_1, mediumLoad, highLoad} = useLoad();
if (!mediumLoad && !highLoad) {
return fallback;
}
// Only return the icon if the load is not low.
const color = highLoad ? 'red' : 'yellow';
let icon = <Link to='/admin/status'>
<Icon name='tachometer alternate' size={size} color={color}/>
</Link>;
return <Popup content={`Load: ${minute_1}`} trigger={icon}/>
}
export function useTitle(title) {
const documentDefined = typeof document !== 'undefined';
const originalTitle = React.useRef(documentDefined ? document.title : null);
@ -1950,3 +1910,11 @@ export function getDistinctColor(hexColors) {
// If we've tried maxAttempts times, return the last generated color regardless
return hslToHex(newColor.h, newColor.s, newColor.l);
}
export const isReactChildNull = (children) => {
// Returns `true` if a React element returns `null` as it's child.
const nonNullChildren = React.Children.map(children,
(child) => React.isValidElement(child) && child.type(child.props)
);
return nonNullChildren.length === 0;
}

View file

@ -99,7 +99,7 @@ const ViewerMessage = () => {
function SlowImportMessage() {
const {status} = useContext(StatusContext);
if (status && status['cpu_info'] && status['cpu_info']['temperature'] >= 80) {
if (status && status['cpu_stats'] && status['cpu_stats']['temperature'] >= 80) {
return <Message warning icon>
<SIcon name='exclamation'/>
<Message.Content>

View file

@ -2,11 +2,11 @@ import React from "react";
import {Link, NavLink} from "react-router-dom";
import {Dropdown, Icon as SIcon, Menu} from "semantic-ui-react";
import {Media, SettingsContext, StatusContext, ThemeContext} from "../contexts/contexts";
import {CPUTemperatureIcon, DarkModeToggle, HotspotStatusIcon, SystemLoadIcon, useLocalStorage} from "./Common";
import {DarkModeToggle, HotspotStatusIcon, isReactChildNull, useLocalStorage} from "./Common";
import {ShareButton} from "./Share";
import {useWROLMode} from "../hooks/customHooks";
import {useCPUTemperature, useIOStats, useLoad, useMemoryStats, usePowerStats, useWROLMode} from "../hooks/customHooks";
import {SearchIconButton} from "./Search";
import {Icon} from "./Theme";
import {Icon, Popup} from "./Theme";
import {HELP_VIEWER_URI, NAME} from "./Vars";
import _ from "lodash";
@ -59,15 +59,11 @@ function MenuLink({link}) {
}
}
function NavIconWrapper(props) {
if (_.isEmpty(props.children)) {
return <></>
} else {
if (props.name === 'warning') {
// console.log(props.name, props.children);
}
return <div style={{marginTop: '0.8em', marginLeft: '1.5em'}}>{props.children}</div>
}
function NavIconWrapper({children}) {
// Do not add margins around empty react element to avoid filling up navbar.
const emptyChild = !children || isReactChildNull(children);
const style = emptyChild ? {} : {marginTop: '0.8em', marginLeft: '1.5em'};
return <div style={style}>{children}</div>
}
function useNavColorSetting() {
@ -97,8 +93,74 @@ export function NavBar() {
{topNavText}
</NavLink>;
// Display the temperature icon first because it can cause the system to throttle.
const warningIcon = <CPUTemperatureIcon fallback={<SystemLoadIcon/>}/>;
// Red/Yellow colors will blend in to some navbar colors, swap the colors for high contrast.
const conflictingColors = ['red', 'orange', 'yellow', 'olive', 'pink'];
const lowWarningColor = conflictingColors.includes(navColor) ? 'white' : 'yellow';
const highWarningColor = conflictingColors.includes(navColor) ? 'black' : 'red';
// Generic system load, the least important warning.
const {minute_1, mediumLoad, highLoad} = useLoad();
let systemLoadIcon;
if (mediumLoad || highLoad) {
// System load is high, display a warning icon.
const color = highLoad ? highWarningColor : lowWarningColor;
const icon = <Link to='/admin/status'>
<Icon name='tachometer alternate' size='large' color={color}/>
</Link>;
systemLoadIcon = <Popup content={`Load: ${minute_1}`} trigger={icon}/>
}
// RAM consumption.
const {percent: memoryPercent} = useMemoryStats();
let memoryIcon;
if (memoryPercent > 80) {
const color = memoryPercent > 90 ? highWarningColor : lowWarningColor;
const icon = <Link to='/admin/status' color={color}>
<Icon name='microchip' size='large'/>
</Link>;
memoryIcon = <Popup content={`System Memory: ${memoryPercent}%`} trigger={icon}/>
}
// Any disk is busy and processes are waiting.
const {percentIOWait} = useIOStats();
let diskWaitIcon;
if (percentIOWait >= 50) {
// Processes are waiting on disk, display a warning icon.
const color = percentIOWait > 75 ? highWarningColor : lowWarningColor;
const icon = <Link to='/admin/status' color={color}>
<Icon name='disk' size='large'/>
</Link>;
diskWaitIcon = <Popup content={`Processes waiting on disk: ${percentIOWait}`} trigger={icon}/>
}
// CPU temperature.
const {temperature, highTemperature, criticalTemperature} = useCPUTemperature();
let temperatureIcon;
if (temperature && temperature >= highTemperature) {
// CPU temperature is high, display a warning icon.
const color = temperature >= criticalTemperature ? highWarningColor : lowWarningColor;
const name = temperature >= criticalTemperature ? 'thermometer' : 'thermometer half';
const icon = <Icon data-testid='cpuTemperatureIcon' name={name} size='large' color={color}/>
const link = <Link to='/admin/status'>{icon}</Link>;
temperatureIcon = <Popup content={`CPU: ${temperature}°C`} trigger={link}/>;
}
// Power issues, this is always displayed if detected.
const {underVoltage, overCurrent} = usePowerStats();
let powerIcon;
if (underVoltage || overCurrent) {
const name = underVoltage ? 'power cord' : 'lightning';
const icon = <Icon name={name} size='large' color={highWarningColor}/>;
const message = underVoltage
? 'Under-voltage detected! Your power supply is insufficient!'
: 'Over-current detected! Your peripherals are using too much power!';
powerIcon = <Popup content={message} trigger={icon}/>;
}
// 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;
let processingLink;
if (status && status.flags) {
@ -115,11 +177,12 @@ export function NavBar() {
</Link>;
const icons = <React.Fragment>
<NavIconWrapper name='processing'>{processingIcon}</NavIconWrapper>
<NavIconWrapper name='warning'>{warningIcon}</NavIconWrapper>
<NavIconWrapper name='share'><ShareButton/></NavIconWrapper>
<NavIconWrapper name='hotspot'><HotspotStatusIcon/></NavIconWrapper>
<NavIconWrapper name='dark mode'><DarkModeToggle/></NavIconWrapper>
<NavIconWrapper>{processingIcon}</NavIconWrapper>
<NavIconWrapper>{powerIcon}</NavIconWrapper>
<NavIconWrapper>{warningIcon}</NavIconWrapper>
<NavIconWrapper><ShareButton/></NavIconWrapper>
<NavIconWrapper><HotspotStatusIcon/></NavIconWrapper>
<NavIconWrapper><DarkModeToggle/></NavIconWrapper>
</React.Fragment>;
return <>