From 6bb44cae8b30bdca85cae9464bf16fe7e914a76f Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sun, 24 May 2026 11:41:59 -0400 Subject: [PATCH] =?UTF-8?q?varaverk:=20Docker=20memory=20=E2=80=94=20use?= =?UTF-8?q?=20docker=20stats=20sum=20instead=20of=20raw=20cgroup=20(matche?= =?UTF-8?q?s=20Unraid=20dashboard)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/varaverk/include/monitor.php | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php b/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php index 5fa4e6d..687af05 100644 --- a/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php +++ b/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php @@ -124,23 +124,18 @@ function vv_memory_breakdown(): array { if (preg_match('/^size\s+\d+\s+(\d+)/', $line, $m)) { $arcKb = (int)($m[1] / 1024); break; } } - // Docker — try paths in order: Unraid cgv2, systemd cgv2 scopes, cgv1 + // Docker — sum docker stats used memory per container (matches Unraid dashboard) $dockerKb = 0; - $cgCandidates = [ - '/sys/fs/cgroup/docker/memory.current', - '/sys/fs/cgroup/memory/docker/memory.usage_in_bytes', - ]; - foreach ($cgCandidates as $path) { - if (file_exists($path)) { - $dockerKb = (int)((float)@file_get_contents($path) / 1024); - break; - } - } - if ($dockerKb === 0) { - foreach (glob('/sys/fs/cgroup/system.slice/docker-*.scope/memory.current') ?: [] as $f) { - $v = @file_get_contents($f); - if ($v !== false) $dockerKb += (int)((float)$v / 1024); - } + $dsOut = shell_exec("docker stats --no-stream --format '{{.MemUsage}}' 2>/dev/null") ?: ''; + foreach (explode("\n", trim($dsOut)) as $line) { + if (!preg_match('/^([0-9.]+)(GiB|MiB|KiB|B)\s*\//', trim($line), $m)) continue; + $val = (float)$m[1]; + $dockerKb += match($m[2]) { + 'GiB' => (int)($val * 1048576), + 'MiB' => (int)($val * 1024), + 'KiB' => (int)$val, + default => (int)($val / 1024), + }; } // VM (QEMU/KVM RSS)