v1.2.48 - Add CPU% and MEM% ASCII bar graphs to API page stats

This commit is contained in:
Your Name
2026-02-25 07:33:06 -04:00
parent 63bc526163
commit b6ff4150b4
4 changed files with 50 additions and 9 deletions
+26 -4
View File
@@ -4500,15 +4500,30 @@ function updateStatsFromCpuMonitoringEvent(monitoringData) {
updateStatsCell('memory-usage', monitoringData.memory_usage_mb.toFixed(1) + ' MB');
}
// MEM% bar using memory_percent from server
if (monitoringData.memory_percent !== undefined) {
const memPct = Math.min(100, Math.max(0, monitoringData.memory_percent));
updateStatsCell('memory-usage', monitoringData.memory_usage_mb.toFixed(1) + ' MB ' + makeAsciiBar(memPct));
}
if (monitoringData.current_cpu_core !== undefined) {
updateStatsCell('cpu-core', 'Core ' + monitoringData.current_cpu_core);
}
// Calculate CPU usage percentage if we have the data
// CPU% using delta between samples
if (monitoringData.process_cpu_time !== undefined && monitoringData.system_cpu_time !== undefined) {
// For now, just show the raw process CPU time (simplified)
// In a real implementation, you'd calculate deltas over time
updateStatsCell('cpu-usage', monitoringData.process_cpu_time + ' ticks');
if (window._prevCpuSample) {
const procDelta = monitoringData.process_cpu_time - window._prevCpuSample.proc;
const sysDelta = monitoringData.system_cpu_time - window._prevCpuSample.sys;
if (sysDelta > 0) {
const cpuPct = Math.min(100, Math.max(0, (procDelta / sysDelta) * 100));
updateStatsCell('cpu-usage', makeAsciiBar(cpuPct));
}
}
window._prevCpuSample = {
proc: monitoringData.process_cpu_time,
sys: monitoringData.system_cpu_time
};
}
} catch (error) {
@@ -4898,6 +4913,13 @@ function formatTimestamp(timestamp) {
return date.toLocaleString();
}
// Generate ASCII progress bar: [###############.....] 75%
function makeAsciiBar(pct) {
const filled = Math.round(pct / 5); // 20 chars = 100%
const empty = 20 - filled;
return '[' + '#'.repeat(filled) + '.'.repeat(empty) + '] ' + pct.toFixed(1) + '%';
}
// Update statistics cell with flash animation if value changed
function updateStatsCell(cellId, newValue) {
const cell = document.getElementById(cellId);