diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 44e88ac4..a62011bc 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -781,7 +781,7 @@ export function InfoPopup({ iconSize = null, header = '', iconStyle = {marginLeft: '0.25em', marginRight: '0.25em', marginTop: '-0.5em'}, - ...props + ...props }) { const trigger = ; return } +function IOWaitStatistic({percent_iowait, ...props}) { + if (percent_iowait === null || percent_iowait === undefined) { + return + } + if (percent_iowait >= 30) { + props['color'] = 'red'; + } else if (percent_iowait >= 10) { + props['color'] = 'orange'; + } + return +} + export function BandwidthProgress({label = '', bytes, maxBytes, ...props}) { // Gigabit by default. maxBytes = maxBytes || 125_000_000; @@ -203,9 +215,10 @@ export function StatusPage() { let diskBandwidthStats = []; let memoryPercent; let memorySize; + let percent_iowait; if (status && status['cpu_stats']) { - const {cpu_stats, load_stats, memory_stats, processes_stats} = status; + const {cpu_stats, load_stats, memory_stats, processes_stats, iostat_stats} = status; percent = cpu_stats['percent']; cores = cpu_stats['cores'] || '?'; temperature = cpu_stats['temperature']; @@ -223,6 +236,11 @@ export function StatusPage() { memoryPercent = Math.round(memory_stats['used'] / memory_stats['total'] * 100); memorySize = humanFileSize(memory_stats['total'], 0); + + // Extract IO wait from iostat stats + if (iostat_stats) { + percent_iowait = iostat_stats['percent_iowait']; + } } const SizedHeader = ({children, sizeMobile = 'h1', sizeTablet = 'h2'}) => { @@ -248,7 +266,7 @@ export function StatusPage() { {cpuProgress} {memoryUsageProgress} - + + @@ -265,7 +284,7 @@ export function StatusPage() { {cpuProgress} {memoryUsageProgress} - + + diff --git a/controller/api/status.py b/controller/api/status.py index a224ec8b..c7bd68eb 100644 --- a/controller/api/status.py +++ b/controller/api/status.py @@ -143,3 +143,14 @@ async def get_power(request: Request): if cached and cached.get("power_stats"): return JSONResponse(content=cached["power_stats"]) return JSONResponse(content=get_power_status()) + + +@router.get("/iostat") +async def get_iostat(request: Request): + """Get IO statistics (iowait, user, system, idle percentages).""" + cached = get_cached_status(request) + if cached and cached.get("iostat_stats"): + return JSONResponse(content=cached["iostat_stats"]) + # Fallback to direct call + from controller.lib.status import get_iostat_status + return JSONResponse(content=get_iostat_status()) diff --git a/controller/lib/status.py b/controller/lib/status.py index 6294ff5b..cb1f790c 100644 --- a/controller/lib/status.py +++ b/controller/lib/status.py @@ -226,11 +226,13 @@ def get_power_status() -> dict: def get_iostat_status() -> dict: """ - Get IO statistics using iostat command. + Get IO statistics using iostat command, with psutil fallback. Returns format compatible with main API's iostat_stats: dict with keys: percent_idle, percent_iowait, percent_nice, percent_steal, percent_system, percent_user + + Note: iowait is Linux-specific. On macOS, percent_iowait will be None. """ import subprocess @@ -243,6 +245,7 @@ def get_iostat_status() -> dict: "percent_user": None, } + # Try iostat + jc first (Linux) try: # Run iostat with 1 second interval, 2 counts (use second measurement) proc = subprocess.run( @@ -267,12 +270,28 @@ def get_iostat_status() -> dict: "percent_system": cpu_stats.get('percent_system'), "percent_user": cpu_stats.get('percent_user'), } + if result["percent_iowait"] is not None: + return result except ImportError: - # jc not available, parse manually + # jc not available, try psutil fallback pass except Exception: pass + # Fallback to psutil (cross-platform, but iowait only on Linux) + try: + cpu = psutil.cpu_times_percent(interval=1) + result = { + "percent_idle": getattr(cpu, 'idle', None), + "percent_iowait": getattr(cpu, 'iowait', None), # None on macOS + "percent_nice": getattr(cpu, 'nice', None), + "percent_steal": getattr(cpu, 'steal', None), + "percent_system": getattr(cpu, 'system', None), + "percent_user": getattr(cpu, 'user', None), + } + except Exception: + pass + return result diff --git a/controller/main.py b/controller/main.py index b70111f8..a659a488 100644 --- a/controller/main.py +++ b/controller/main.py @@ -34,6 +34,7 @@ from controller.lib.docker_services import ( ) from controller.lib.status import ( get_cpu_status, + get_iostat_status, get_load_status, get_memory_status, get_primary_drive_status, @@ -116,6 +117,7 @@ async def dashboard(request: Request): cpu = cached.get("cpu_stats") or {} memory = cached.get("memory_stats") or {} load = cached.get("load_stats") or {} + iostat = cached.get("iostat_stats") or {} drives = cached.get("drives_stats") or [] primary_drive = None for drive in drives: @@ -127,6 +129,7 @@ async def dashboard(request: Request): cpu = get_cpu_status() memory = get_memory_status() load = get_load_status() + iostat = get_iostat_status() primary_drive = get_primary_drive_status() # Format storage data @@ -166,6 +169,9 @@ async def dashboard(request: Request): "load_1min": load["minute_1"], # Field renamed }, "storage": storage, + "iostat": { + "percent_iowait": iostat.get("percent_iowait"), + }, # Real service status "services": services, diff --git a/controller/templates/index.html b/controller/templates/index.html index 56e14615..9e3f97e4 100644 --- a/controller/templates/index.html +++ b/controller/templates/index.html @@ -628,6 +628,11 @@

{{ storage.percent|default('--') }}%

{{ storage.free_gb|default('--') }} GB free

+
+

IO Wait

+

{{ iostat.percent_iowait|default('--') }}%

+

disk waiting

+
@@ -1470,11 +1475,12 @@ async function updateSystemStatus() { try { // Fetch all stats endpoints in parallel - const [cpu, memory, load, primaryDrive] = await Promise.all([ + const [cpu, memory, load, primaryDrive, iostat] = await Promise.all([ apiCall('api/stats/cpu'), apiCall('api/stats/memory'), apiCall('api/stats/load'), apiCall('api/stats/drives/primary'), + apiCall('api/stats/iostat'), ]); // Update CPU card @@ -1512,6 +1518,26 @@ const freeGb = (freeBytes / (1024 ** 3)).toFixed(1); storageSub.textContent = freeGb + ' GB free'; } + + // Update IO Wait card + const iowaitValue = document.getElementById('iowait-value'); + if (iowaitValue) { + const iowait = iostat.percent_iowait; + if (iowait !== null && iowait !== undefined) { + iowaitValue.textContent = iowait.toFixed(1) + '%'; + // Color based on IO wait severity + if (iowait >= 30) { + iowaitValue.style.color = '#ff6b6b'; // Red + } else if (iowait >= 10) { + iowaitValue.style.color = '#ffd93d'; // Yellow + } else { + iowaitValue.style.color = '#4ecca3'; // Green (default) + } + } else { + iowaitValue.textContent = '--%'; + iowaitValue.style.color = '#4ecca3'; + } + } } catch (e) { console.error('Failed to update system status:', e); }