cli/command/container: use per-stats OSType if present

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-27 16:29:47 +01:00
parent 6ed16a2cc1
commit 83319f09f7
2 changed files with 8 additions and 0 deletions

View File

@ -109,6 +109,8 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
apiClient := dockerCLI.Client()
// Get the daemonOSType to handle platform-specific stats fields.
// This value is used as a fallback for docker < v29, which did not
// include the OSType field per stats.
daemonOSType = dockerCLI.ServerInfo().OSType
// waitFirst is a WaitGroup to wait first stat data's reach for each container

View File

@ -88,6 +88,12 @@ func collect(ctx context.Context, s *Stats, cli client.ContainerAPIClient, strea
continue
}
// Daemon versions before v29 did not return per-stats OSType;
// fall back to using the daemon's OSType.
if v.OSType == "" {
v.OSType = daemonOSType
}
if daemonOSType == "windows" {
netRx, netTx := calculateNetwork(v.Networks)
s.SetStatistics(StatsEntry{