Skip to content

Commit 83319f0

Browse files
committed
cli/command/container: use per-stats OSType if present
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 6ed16a2 commit 83319f0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

cli/command/container/stats.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
109109
apiClient := dockerCLI.Client()
110110

111111
// Get the daemonOSType to handle platform-specific stats fields.
112+
// This value is used as a fallback for docker < v29, which did not
113+
// include the OSType field per stats.
112114
daemonOSType = dockerCLI.ServerInfo().OSType
113115

114116
// waitFirst is a WaitGroup to wait first stat data's reach for each container

cli/command/container/stats_helpers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func collect(ctx context.Context, s *Stats, cli client.ContainerAPIClient, strea
8888
continue
8989
}
9090

91+
// Daemon versions before v29 did not return per-stats OSType;
92+
// fall back to using the daemon's OSType.
93+
if v.OSType == "" {
94+
v.OSType = daemonOSType
95+
}
96+
9197
if daemonOSType == "windows" {
9298
netRx, netTx := calculateNetwork(v.Networks)
9399
s.SetStatistics(StatsEntry{

0 commit comments

Comments
 (0)