summaryrefslogtreecommitdiff
path: root/libpod/stats.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-02-28 10:02:54 -0600
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-28 16:46:29 +0000
commit7ffc89d71a65da32c74cf6ec3aeb99b0d547ebd1 (patch)
tree1593b5f562cab241a47d148e401f3c7c309883dd /libpod/stats.go
parent2a59653bf3d5230a8be1a20ed9fcf53a185afba3 (diff)
downloadpodman-7ffc89d71a65da32c74cf6ec3aeb99b0d547ebd1.tar.gz
podman-7ffc89d71a65da32c74cf6ec3aeb99b0d547ebd1.tar.bz2
podman-7ffc89d71a65da32c74cf6ec3aeb99b0d547ebd1.zip
podman stats add networking
Add networking information to podman stats output. Also correct an issue filed where memory constraints of the cgroup were not reflected in the stats output. And finally, fix issue with PID count. Resolves issue #364 Signed-off-by: baude <bbaude@redhat.com> Closes: #417 Approved by: mheon
Diffstat (limited to 'libpod/stats.go')
-rw-r--r--libpod/stats.go34
1 files changed, 23 insertions, 11 deletions
diff --git a/libpod/stats.go b/libpod/stats.go
index faccc2366..f4694923c 100644
--- a/libpod/stats.go
+++ b/libpod/stats.go
@@ -6,8 +6,10 @@ import (
"time"
"github.com/containerd/cgroups"
- "github.com/opencontainers/runc/libcontainer"
+ "github.com/containernetworking/plugins/pkg/ns"
+ "github.com/cri-o/ocicni/pkg/ocicni"
"github.com/pkg/errors"
+ "github.com/vishvananda/netlink"
)
// ContainerStats contains the statistics information for a running container
@@ -55,6 +57,11 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container
return stats, errors.Wrapf(err, "unable to determine container state")
}
+ netStats, err := getContainerNetIO(c)
+ if err != nil {
+ return nil, err
+ }
+
previousCPU := previousStats.CPUNano
previousSystem := previousStats.SystemNano
stats.CPU = calculateCPUPercent(cgroupStats, previousCPU, previousSystem)
@@ -63,13 +70,14 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container
stats.MemPerc = (float64(stats.MemUsage) / float64(stats.MemLimit)) * 100
stats.PIDs = 0
if conState == ContainerStateRunning {
- stats.PIDs = cgroupStats.Pids.Current - 1
+ stats.PIDs = cgroupStats.Pids.Current
}
stats.BlockInput, stats.BlockOutput = calculateBlockIO(cgroupStats)
stats.CPUNano = cgroupStats.CPU.Usage.Total
stats.SystemNano = cgroupStats.CPU.Usage.Kernel
- // TODO Figure out where to get the Netout stuff.
- //stats.NetInput, stats.NetOutput = getContainerNetIO(cgroupStats)
+ stats.NetInput = netStats.TxBytes
+ stats.NetOutput = netStats.RxBytes
+
return stats, nil
}
@@ -90,13 +98,17 @@ func getMemLimit(cgroupLimit uint64) uint64 {
return cgroupLimit
}
-// Returns the total number of bytes transmitted and received for the given container stats
-func getContainerNetIO(stats *libcontainer.Stats) (received uint64, transmitted uint64) { //nolint
- for _, iface := range stats.Interfaces {
- received += iface.RxBytes
- transmitted += iface.TxBytes
- }
- return
+func getContainerNetIO(ctr *Container) (*netlink.LinkStatistics, error) {
+ var netStats *netlink.LinkStatistics
+ err := ns.WithNetNSPath(ctr.state.NetNS.Path(), func(_ ns.NetNS) error {
+ link, err := netlink.LinkByName(ocicni.DefaultInterfaceName)
+ if err != nil {
+ return err
+ }
+ netStats = link.Attrs().Statistics
+ return nil
+ })
+ return netStats, err
}
func calculateCPUPercent(stats *cgroups.Metrics, previousCPU, previousSystem uint64) float64 {