{"record":{"id":"b6b0fc1c68d66435","repo":"henrygd/beszel","slug":"s-w-see-https-github-com-henrygd-beszel-is","errorCode":null,"errorMessage":"%s - %w - see https://github.com/henrygd/beszel/issues/144","messagePattern":"(.+?) - %w - see https://github\\.com/henrygd/beszel/issues/144","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/docker.go","lineNumber":566,"sourceCode":"\t// Podman reports system_cpu_usage from cgroup cpu.stat (not /proc/stat), so it reflects\n\t// only cgroup-tracked activity rather than total host capacity. Use a time-based method\n\t// instead so the result is comparable to host CPU utilization. See:\n\t// https://github.com/henrygd/beszel/issues/2049\n\tvar cpuPct float64\n\tif dm.isWindows {\n\t\tprevRead := dm.lastCpuReadTime[cacheTimeMs][ctr.IdShort]\n\t\tcpuPct = res.CalculateCpuPercentWindows(prevCpuContainer, prevRead)\n\t} else if dm.usingPodman && res.CPUStats.OnlineCPUs > 0 {\n\t\tprevRead := dm.lastCpuReadTime[cacheTimeMs][ctr.IdShort]\n\t\tcpuPct = res.CalculateCpuPercentPodman(prevCpuContainer, prevRead)\n\t} else {\n\t\tcpuPct = res.CalculateCpuPercentLinux(prevCpuContainer, prevCpuSystem)\n\t}\n\n\t// Calculate memory usage\n\tusedMemory, err := calculateMemoryUsage(res, dm.isWindows)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s - %w - see https://github.com/henrygd/beszel/issues/144\", name, err)\n\t}\n\n\t// Store current CPU stats for next calculation\n\tcurrentCpuContainer := res.CPUStats.CPUUsage.TotalUsage\n\tcurrentCpuSystem := res.CPUStats.SystemUsage\n\tdm.setCpuCurrentValues(cacheTimeMs, ctr.IdShort, currentCpuContainer, currentCpuSystem)\n\n\t// Validate CPU percentage\n\tif err := validateCpuPercentage(cpuPct, name); err != nil {\n\t\treturn err\n\t}\n\n\t// Calculate network stats using DeltaTracker\n\tsent_delta, recv_delta := dm.calculateNetworkStats(ctr, res, name, cacheTimeMs)\n\n\t// Store per-cache-time network read time for next rate calculation\n\tif dm.lastNetworkReadTime[cacheTimeMs] == nil {\n\t\tdm.lastNetworkReadTime[cacheTimeMs] = make(map[string]time.Time)","sourceCodeStart":548,"sourceCodeEnd":584,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/agent/docker.go#L548-L584","documentation":"updateContainerStats computes memory usage from the Docker/Podman stats response via calculateMemoryUsage. When that calculation fails (usually because the stats payload lacks expected memory fields), the error is wrapped with the container name and a link to beszel issue #144. This is a known quirk where Podman (or cgroup-v2-only setups) reports memory stats differently from Docker.","triggerScenarios":"calculateMemoryUsage returns an error while processing a stats response — e.g. memory_stats missing or zeroed, cache/usage fields absent, which happens with certain Podman versions and rootless/cgroup-v2 configurations.","commonSituations":"Running the agent against Podman sockets where stats JSON omits or renames memory fields; kernels with cgroup v2 where some memory stats are not exposed; containers that just exited mid-stats-read returning partial data.","solutions":["Check beszel issue #144 for the exact Podman/cgroup version affected and workarounds","Update Podman/Docker to a version that reports memory_stats.usage correctly","Verify cgroup controller availability (memory controller enabled for the agent's cgroup)","Guard the stats loop so one container's memory-parse failure does not abort other containers"],"exampleFix":"// before: whole update fails on memory calc\nusedMemory, err := calculateMemoryUsage(res, dm.isWindows)\nif err != nil {\n    return fmt.Errorf(\"%s - %w - see https://github.com/henrygd/beszel/issues/144\", name, err)\n}\n// after: degrade gracefully\nusedMemory, err := calculateMemoryUsage(res, dm.isWindows)\nif err != nil {\n    log.Debug(\"memory stats unavailable\", \"container\", name, \"err\", err)\n    usedMemory = 0\n}","handlingStrategy":"try-catch","validationCode":"// sanity-check the stats payload before computing memory\nif len(res.MemoryStats.Stats) == 0 || res.MemoryStats.Usage == 0 {\n    // skip memory calculation for this sample\n}","typeGuard":null,"tryCatchPattern":"if err := updateContainerStats(ctr); err != nil {\n    if strings.Contains(err.Error(), \"issues/144\") {\n        log.Debug(\"podman memory stats unsupported\", \"container\", ctr.Name)\n    } else {\n        log.Error(\"stats update failed\", \"err\", err)\n    }\n}","preventionTips":["Keep Podman/Docker versions current (see beszel issue #144)","Verify cgroup v2 memory controller is enabled","Don't abort the whole stats loop when one container's memory parse fails"],"tags":["docker","podman","memory-stats"],"backgroundTag":"stats-payload-parse-failed","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}