varaverk: memory card — top 5 procs by RSS as horizontal strip under total

This commit is contained in:
Gmer4Lfe
2026-05-24 11:25:27 -04:00
parent 475cb3e75c
commit 397ec405a0
2 changed files with 21 additions and 15 deletions
@@ -145,6 +145,19 @@ function vv_memory_breakdown(): array {
$freeKb = max(0, $mem['MemAvailable'] ?? 0);
$systemKb = max(0, $totalKb - $freeKb - $arcKb - $dockerKb - $vmKb);
// Top processes by RSS — group same-named procs, take top 5
$grouped = [];
$psOut = shell_exec("ps -eo comm,rss --sort=-rss 2>/dev/null | tail -n +2 | head -40") ?: '';
foreach (explode("\n", trim($psOut)) as $line) {
$parts = preg_split('/\s+/', trim($line), 2);
if (count($parts) === 2 && is_numeric($parts[1]) && (int)$parts[1] > 0)
$grouped[$parts[0]] = ($grouped[$parts[0]] ?? 0) + (int)$parts[1];
}
arsort($grouped);
$topProcs = [];
foreach (array_slice($grouped, 0, 5, true) as $name => $kb)
$topProcs[] = ['name' => $name, 'kb' => $kb];
return [
'total_kb' => $totalKb,
'system_kb' => $systemKb,
@@ -152,6 +165,7 @@ function vv_memory_breakdown(): array {
'zfs_kb' => $arcKb,
'docker_kb' => $dockerKb,
'free_kb' => $freeKb,
'top_procs' => $topProcs,
];
}