Merge pull request #27105 from markjdb/main

A couple of minor stats improvements for FreeBSD
This commit is contained in:
openshift-merge-bot[bot]
2025-09-19 14:07:22 +00:00
committed by GitHub
2 changed files with 7 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/containers/podman/v5/pkg/rctl" "github.com/containers/podman/v5/pkg/rctl"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"go.podman.io/storage/pkg/system" "go.podman.io/storage/pkg/system"
"golang.org/x/sys/unix"
) )
// getPlatformContainerStats gets the platform-specific running stats // 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) { 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
} }

View File

@ -30,7 +30,7 @@ func statsContainerJSON(ctnr *libpod.Container, stats *define.ContainerStats, pr
TotalUsage: stats.CPUNano, TotalUsage: stats.CPUNano,
}, },
CPU: stats.CPU, CPU: stats.CPU,
OnlineCPUs: 0, OnlineCPUs: uint32(onlineCPUs),
ThrottlingData: container.ThrottlingData{}, ThrottlingData: container.ThrottlingData{},
}, },
PreCPUStats: preCPUStats, PreCPUStats: preCPUStats,