Putting iostat on dashboards.
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

This commit is contained in:
Roland 2025-12-24 15:45:53 -07:00
parent 5d50562768
commit 5fb49ad001
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
6 changed files with 89 additions and 7 deletions

View file

@ -781,7 +781,7 @@ export function InfoPopup({
iconSize = null,
header = '',
iconStyle = {marginLeft: '0.25em', marginRight: '0.25em', marginTop: '-0.5em'},
...props
...props
}) {
const trigger = <Icon link name={icon} size={iconSize} style={iconStyle}/>;
return <Popup

View file

@ -84,6 +84,18 @@ function CPUTemperatureStatistic({temperature, high_temperature, critical_temper
return <Statistic label='Temp C°' value={temperature} {...props}/>
}
function IOWaitStatistic({percent_iowait, ...props}) {
if (percent_iowait === null || percent_iowait === undefined) {
return <Statistic label='IO Wait %' value='?'/>
}
if (percent_iowait >= 30) {
props['color'] = 'red';
} else if (percent_iowait >= 10) {
props['color'] = 'orange';
}
return <Statistic label='IO Wait %' value={percent_iowait.toFixed(1)} {...props}/>
}
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() {
<Segment>
{cpuProgress}
{memoryUsageProgress}
<Statistic.Group>
<Statistic.Group size='mini'>
<CPUTemperatureStatistic
id='cpu_temperature_statistic'
temperature={temperature}
@ -258,6 +276,7 @@ export function StatusPage() {
<LoadStatistic label='1 Minute Load' value={minute_1} cores={cores}/>
<LoadStatistic label='5 Minute Load' value={minute_5} cores={cores}/>
<LoadStatistic label='15 Minute Load' value={minute_15} cores={cores}/>
<IOWaitStatistic percent_iowait={percent_iowait}/>
</Statistic.Group>
</Segment>
</Media>
@ -265,7 +284,7 @@ export function StatusPage() {
<Segment>
{cpuProgress}
{memoryUsageProgress}
<Statistic.Group size='mini'>
<Statistic.Group>
<CPUTemperatureStatistic
id='cpu_temperature_statistic'
temperature={temperature}
@ -276,6 +295,7 @@ export function StatusPage() {
<LoadStatistic label='1 Min. Load' value={minute_1} cores={cores}/>
<LoadStatistic label='5 Min.' value={minute_5} cores={cores}/>
<LoadStatistic label='15 Min.' value={minute_15} cores={cores}/>
<IOWaitStatistic percent_iowait={percent_iowait}/>
</Statistic.Group>
</Segment>
</Media>

View file

@ -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())

View file

@ -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

View file

@ -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,

View file

@ -628,6 +628,11 @@
<p class="value">{{ storage.percent|default('--') }}%</p>
<p class="sub">{{ storage.free_gb|default('--') }} GB free</p>
</div>
<div class="status-card">
<h3>IO Wait</h3>
<p class="value" id="iowait-value">{{ iostat.percent_iowait|default('--') }}%</p>
<p class="sub">disk waiting</p>
</div>
</div>
</section>
@ -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);
}