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)