From 602ba415c69e8921033f75ceed8a3dddd87381e0 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 16 Sep 2025 14:44:39 +0000 Subject: [PATCH 1/2] libpod: Implement getOnlineCPUs() on FreeBSD Include an explicit container state check. Otherwise the containers/stats endpoint will return all-zero stats for a stopped container even when in non-streaming mode, which breaks some consumers of the API, particularly nomad's podman driver. Implement the interface by just returning the number of host CPUs. A bit more sophisticated would be to fetch the jail's cpuset, but it's not very important for now. Signed-off-by: Mark Johnston --- libpod/stats_freebsd.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libpod/stats_freebsd.go b/libpod/stats_freebsd.go index 47933269c1..2f7dca63ed 100644 --- a/libpod/stats_freebsd.go +++ b/libpod/stats_freebsd.go @@ -11,6 +11,7 @@ import ( "github.com/containers/podman/v5/pkg/rctl" "github.com/sirupsen/logrus" "go.podman.io/storage/pkg/system" + "golang.org/x/sys/unix" ) // getPlatformContainerStats gets the platform-specific running stats @@ -127,5 +128,9 @@ func calculateCPUPercent(currentCPU, previousCPU, now, previousSystem uint64) fl } func getOnlineCPUs(container *Container) (int, error) { - return 0, nil + if container.state.State != define.ContainerStateRunning { + return -1, fmt.Errorf("container %s is not running: %w", container.ID(), define.ErrCtrStopped) + } + n, err := unix.SysctlUint32("hw.ncpu") + return int(n), err } From a0238fb19f28db1c935349e4c0e6edb38e9300d9 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Thu, 18 Sep 2025 14:22:37 +0000 Subject: [PATCH 2/2] libpod: Fill out OnlineCPUs in the FreeBSD stats handler Signed-off-by: Mark Johnston --- pkg/api/handlers/compat/containers_stats_freebsd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api/handlers/compat/containers_stats_freebsd.go b/pkg/api/handlers/compat/containers_stats_freebsd.go index 9ff8f788f6..637c285e11 100644 --- a/pkg/api/handlers/compat/containers_stats_freebsd.go +++ b/pkg/api/handlers/compat/containers_stats_freebsd.go @@ -30,7 +30,7 @@ func statsContainerJSON(ctnr *libpod.Container, stats *define.ContainerStats, pr TotalUsage: stats.CPUNano, }, CPU: stats.CPU, - OnlineCPUs: 0, + OnlineCPUs: uint32(onlineCPUs), ThrottlingData: container.ThrottlingData{}, }, PreCPUStats: preCPUStats,