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 } 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,