@@ -13,6 +13,7 @@ import (
1313
1414 "github.com/containers/buildah/pkg/jail"
1515 "github.com/containers/common/libnetwork/types"
16+ "github.com/containers/podman/v4/libpod/define"
1617 "github.com/containers/storage/pkg/lockfile"
1718 "github.com/sirupsen/logrus"
1819)
@@ -45,33 +46,6 @@ type NetstatAddress struct {
4546 Collisions uint64 `json:"collisions"`
4647}
4748
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-
7549type RootlessNetNS struct {
7650 dir string
7751 Lock * lockfile.LockFile
@@ -223,7 +197,7 @@ func (r *Runtime) teardownNetNS(ctr *Container) error {
223197
224198// TODO (5.0): return the statistics per network interface
225199// This would allow better compat with docker.
226- func getContainerNetIO (ctr * Container ) (* LinkStatistics64 , error ) {
200+ func getContainerNetIO (ctr * Container ) (map [ string ]define. ContainerNetworkStats , error ) {
227201 if ctr .state .NetNS == "" {
228202 // If NetNS is nil, it was set as none, and no netNS
229203 // was set up this is a valid state and thus return no
@@ -249,8 +223,9 @@ func getContainerNetIO(ctr *Container) (*LinkStatistics64, error) {
249223 return nil , err
250224 }
251225
226+ res := make (map [string ]define.ContainerNetworkStats )
227+
252228 // Sum all the interface stats - in practice only Tx/TxBytes are needed
253- res := & LinkStatistics64 {}
254229 for _ , ifaddr := range stats .Statistics .Interface {
255230 // Each interface has two records, one for link-layer which has
256231 // an MTU field and one for IP which doesn't. We only want the
@@ -260,14 +235,16 @@ func getContainerNetIO(ctr *Container) (*LinkStatistics64, error) {
260235 // if we move to per-interface stats in future, this can be
261236 // reported separately.
262237 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
271248 }
272249 }
273250
0 commit comments