diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-06-02 04:26:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-02 04:26:04 -0400 |
commit | a208bfaa521ada1a3aa66f609de3f8434c80f896 (patch) | |
tree | 0567f7b7b55419b08d5b56bc7187c99b7074cc08 /libpod | |
parent | 2958aee08389aa5e89794f5e5b4f30ac3328d071 (diff) | |
parent | 16e8b2f32ecc0dd071a9303159d5ff8d86e7279f (diff) | |
download | podman-a208bfaa521ada1a3aa66f609de3f8434c80f896.tar.gz podman-a208bfaa521ada1a3aa66f609de3f8434c80f896.tar.bz2 podman-a208bfaa521ada1a3aa66f609de3f8434c80f896.zip |
Merge pull request #14421 from Luap99/stats
podman stats: work with network connect/disconnect
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/networking_linux.go | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index 73e64530e..37fa9b5f5 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -930,6 +930,8 @@ func (r *Runtime) reloadContainerNetwork(ctr *Container) (map[string]types.Statu return r.configureNetNS(ctr, ctr.state.NetNS) } +// TODO (5.0): return the statistics per network interface +// This would allow better compat with docker. func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) { var netStats *netlink.LinkStatistics @@ -943,21 +945,39 @@ func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) { return nil, nil } - // FIXME get the interface from the container netstatus - dev := "eth0" netMode := ctr.config.NetMode + netStatus := ctr.getNetworkStatus() if otherCtr != nil { netMode = otherCtr.config.NetMode + netStatus = otherCtr.getNetworkStatus() } if netMode.IsSlirp4netns() { - dev = "tap0" + // create a fake status with correct interface name for the logic below + netStatus = map[string]types.StatusBlock{ + "slirp4netns": { + Interfaces: map[string]types.NetInterface{"tap0": {}}, + }, + } } err := ns.WithNetNSPath(netNSPath, func(_ ns.NetNS) error { - link, err := netlink.LinkByName(dev) - if err != nil { - return err + for _, status := range netStatus { + for dev := range status.Interfaces { + link, err := netlink.LinkByName(dev) + if err != nil { + return err + } + if netStats == nil { + netStats = link.Attrs().Statistics + continue + } + // Currently only Tx/RxBytes are used. + // In the future we should return all stats per interface so that + // api users have a better options. + stats := link.Attrs().Statistics + netStats.TxBytes += stats.TxBytes + netStats.RxBytes += stats.RxBytes + } } - netStats = link.Attrs().Statistics return nil }) return netStats, err |