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

@ -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);
}