Skip to content

Commit 1671029

Browse files
Merge pull request #27105 from markjdb/main
A couple of minor stats improvements for FreeBSD
2 parents 0215832 + a0238fb commit 1671029

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

libpod/stats_freebsd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/containers/podman/v5/pkg/rctl"
1212
"github.com/sirupsen/logrus"
1313
"go.podman.io/storage/pkg/system"
14+
"golang.org/x/sys/unix"
1415
)
1516

1617
// getPlatformContainerStats gets the platform-specific running stats
@@ -127,5 +128,9 @@ func calculateCPUPercent(currentCPU, previousCPU, now, previousSystem uint64) fl
127128
}
128129

129130
func getOnlineCPUs(container *Container) (int, error) {
130-
return 0, nil
131+
if container.state.State != define.ContainerStateRunning {
132+
return -1, fmt.Errorf("container %s is not running: %w", container.ID(), define.ErrCtrStopped)
133+
}
134+
n, err := unix.SysctlUint32("hw.ncpu")
135+
return int(n), err
131136
}

pkg/api/handlers/compat/containers_stats_freebsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func statsContainerJSON(ctnr *libpod.Container, stats *define.ContainerStats, pr
3030
TotalUsage: stats.CPUNano,
3131
},
3232
CPU: stats.CPU,
33-
OnlineCPUs: 0,
33+
OnlineCPUs: uint32(onlineCPUs),
3434
ThrottlingData: container.ThrottlingData{},
3535
},
3636
PreCPUStats: preCPUStats,

0 commit comments

Comments
 (0)