@@ -13,6 +13,7 @@ import (
13
13
14
14
"github.com/containers/buildah/pkg/jail"
15
15
"github.com/containers/common/libnetwork/types"
16
+ "github.com/containers/podman/v4/libpod/define"
16
17
"github.com/containers/storage/pkg/lockfile"
17
18
"github.com/sirupsen/logrus"
18
19
)
@@ -45,33 +46,6 @@ type NetstatAddress struct {
45
46
Collisions uint64 `json:"collisions"`
46
47
}
47
48
48
- // copied from github.com/vishvanada/netlink which does not build on freebsd
49
- type LinkStatistics64 struct {
50
- RxPackets uint64
51
- TxPackets uint64
52
- RxBytes uint64
53
- TxBytes uint64
54
- RxErrors uint64
55
- TxErrors uint64
56
- RxDropped uint64
57
- TxDropped uint64
58
- Multicast uint64
59
- Collisions uint64
60
- RxLengthErrors uint64
61
- RxOverErrors uint64
62
- RxCrcErrors uint64
63
- RxFrameErrors uint64
64
- RxFifoErrors uint64
65
- RxMissedErrors uint64
66
- TxAbortedErrors uint64
67
- TxCarrierErrors uint64
68
- TxFifoErrors uint64
69
- TxHeartbeatErrors uint64
70
- TxWindowErrors uint64
71
- RxCompressed uint64
72
- TxCompressed uint64
73
- }
74
-
75
49
type RootlessNetNS struct {
76
50
dir string
77
51
Lock * lockfile.LockFile
@@ -223,7 +197,7 @@ func (r *Runtime) teardownNetNS(ctr *Container) error {
223
197
224
198
// TODO (5.0): return the statistics per network interface
225
199
// This would allow better compat with docker.
226
- func getContainerNetIO (ctr * Container ) (* LinkStatistics64 , error ) {
200
+ func getContainerNetIO (ctr * Container ) (map [ string ]define. ContainerNetworkStats , error ) {
227
201
if ctr .state .NetNS == "" {
228
202
// If NetNS is nil, it was set as none, and no netNS
229
203
// was set up this is a valid state and thus return no
@@ -249,8 +223,9 @@ func getContainerNetIO(ctr *Container) (*LinkStatistics64, error) {
249
223
return nil , err
250
224
}
251
225
226
+ res := make (map [string ]define.ContainerNetworkStats )
227
+
252
228
// Sum all the interface stats - in practice only Tx/TxBytes are needed
253
- res := & LinkStatistics64 {}
254
229
for _ , ifaddr := range stats .Statistics .Interface {
255
230
// Each interface has two records, one for link-layer which has
256
231
// an MTU field and one for IP which doesn't. We only want the
@@ -260,14 +235,16 @@ func getContainerNetIO(ctr *Container) (*LinkStatistics64, error) {
260
235
// if we move to per-interface stats in future, this can be
261
236
// reported separately.
262
237
if ifaddr .Mtu > 0 {
263
- res .RxPackets += ifaddr .ReceivedPackets
264
- res .TxPackets += ifaddr .SentPackets
265
- res .RxBytes += ifaddr .ReceivedBytes
266
- res .TxBytes += ifaddr .SentBytes
267
- res .RxErrors += ifaddr .ReceivedErrors
268
- res .TxErrors += ifaddr .SentErrors
269
- res .RxDropped += ifaddr .DroppedPackets
270
- res .Collisions += ifaddr .Collisions
238
+ linkStats := define.ContainerNetworkStats {
239
+ RxPackets : ifaddr .ReceivedPackets ,
240
+ TxPackets : ifaddr .SentPackets ,
241
+ RxBytes : ifaddr .ReceivedBytes ,
242
+ TxBytes : ifaddr .SentBytes ,
243
+ RxErrors : ifaddr .ReceivedErrors ,
244
+ TxErrors : ifaddr .SentErrors ,
245
+ RxDropped : ifaddr .DroppedPackets ,
246
+ }
247
+ res [ifaddr .Name ] = linkStats
271
248
}
272
249
}
273
250
0 commit comments