summaryrefslogtreecommitdiff
path: root/libkpod/stats.go
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2017-12-11 10:20:22 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-12-14 13:56:20 +0000
commit05f4dd9f41707959ce801f9851c79232a1b79dca (patch)
treeed4cfc80c90204f6166379f4f2c368ac57d480f1 /libkpod/stats.go
parent900afc929f01ef2a38b69263e35c964284f1f9f4 (diff)
downloadpodman-05f4dd9f41707959ce801f9851c79232a1b79dca.tar.gz
podman-05f4dd9f41707959ce801f9851c79232a1b79dca.tar.bz2
podman-05f4dd9f41707959ce801f9851c79232a1b79dca.zip
Clear up fragments of the old api
As everything is being moved over to the new container api removing files that depended on the old api Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #116 Approved by: rhatdan
Diffstat (limited to 'libkpod/stats.go')
-rw-r--r--libkpod/stats.go111
1 files changed, 0 insertions, 111 deletions
diff --git a/libkpod/stats.go b/libkpod/stats.go
deleted file mode 100644
index 8e74577d4..000000000
--- a/libkpod/stats.go
+++ /dev/null
@@ -1,111 +0,0 @@
-package libkpod
-
-import (
- "path/filepath"
- "syscall"
- "time"
-
- "strings"
-
- "github.com/opencontainers/runc/libcontainer"
- "github.com/projectatomic/libpod/oci"
-)
-
-// ContainerStats contains the statistics information for a running container
-type ContainerStats struct {
- Container string
- CPU float64
- cpuNano uint64
- systemNano uint64
- MemUsage uint64
- MemLimit uint64
- MemPerc float64
- NetInput uint64
- NetOutput uint64
- BlockInput uint64
- BlockOutput uint64
- PIDs uint64
-}
-
-// GetContainerStats gets the running stats for a given container
-func (c *ContainerServer) GetContainerStats(ctr *oci.Container, previousStats *ContainerStats) (*ContainerStats, error) {
- previousCPU := previousStats.cpuNano
- previousSystem := previousStats.systemNano
- libcontainerStats, err := c.LibcontainerStats(ctr)
- if err != nil {
- return nil, err
- }
- cgroupStats := libcontainerStats.CgroupStats
- stats := new(ContainerStats)
- stats.Container = ctr.ID()
- stats.CPU = calculateCPUPercent(libcontainerStats, previousCPU, previousSystem)
- stats.MemUsage = cgroupStats.MemoryStats.Usage.Usage
- stats.MemLimit = getMemLimit(cgroupStats.MemoryStats.Usage.Limit)
- stats.MemPerc = float64(stats.MemUsage) / float64(stats.MemLimit)
- stats.PIDs = cgroupStats.PidsStats.Current
- stats.BlockInput, stats.BlockOutput = calculateBlockIO(libcontainerStats)
- stats.NetInput, stats.NetOutput = getContainerNetIO(libcontainerStats)
-
- return stats, nil
-}
-
-func loadFactory(root string) (libcontainer.Factory, error) {
- abs, err := filepath.Abs(root)
- if err != nil {
- return nil, err
- }
- cgroupManager := libcontainer.Cgroupfs
- return libcontainer.New(abs, cgroupManager, libcontainer.CriuPath(""))
-}
-
-// getMemory limit returns the memory limit for a given cgroup
-// If the configured memory limit is larger than the total memory on the sys, the
-// physical system memory size is returned
-func getMemLimit(cgroupLimit uint64) uint64 {
- si := &syscall.Sysinfo_t{}
- err := syscall.Sysinfo(si)
- if err != nil {
- return cgroupLimit
- }
-
- physicalLimit := uint64(si.Totalram)
- if cgroupLimit > physicalLimit {
- return physicalLimit
- }
- 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) {
- for _, iface := range stats.Interfaces {
- received += iface.RxBytes
- transmitted += iface.TxBytes
- }
- return
-}
-
-func calculateCPUPercent(stats *libcontainer.Stats, previousCPU, previousSystem uint64) float64 {
- var (
- cpuPercent = 0.0
- cpuDelta = float64(stats.CgroupStats.CpuStats.CpuUsage.TotalUsage - previousCPU)
- systemDelta = float64(uint64(time.Now().UnixNano()) - previousSystem)
- )
- if systemDelta > 0.0 && cpuDelta > 0.0 {
- // gets a ratio of container cpu usage total, multiplies it by the number of cores (4 cores running
- // at 100% utilization should be 400% utilization), and multiplies that by 100 to get a percentage
- cpuPercent = (cpuDelta / systemDelta) * float64(len(stats.CgroupStats.CpuStats.CpuUsage.PercpuUsage)) * 100
- }
- return cpuPercent
-}
-
-func calculateBlockIO(stats *libcontainer.Stats) (read uint64, write uint64) {
- for _, blkIOEntry := range stats.CgroupStats.BlkioStats.IoServiceBytesRecursive {
- switch strings.ToLower(blkIOEntry.Op) {
- case "read":
- read += blkIOEntry.Value
- case "write":
- write += blkIOEntry.Value
- }
- }
- return
-}