From 47258a7093355b8090c8612d2bdc1f45bd748422 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Wed, 7 Oct 2015 10:41:44 -0600 Subject: [PATCH] Godep update: gopsutil --- Godeps/Godeps.json | 28 +++++++++---------- .../shirou/gopsutil/docker/docker_linux.go | 18 +++++++++--- .../shirou/gopsutil/mem/mem_linux.go | 9 +++++- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index af3141d84..7617d4a8e 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -177,38 +177,38 @@ }, { "ImportPath": "github.com/shirou/gopsutil/common", - "Comment": "1.0.0-153-gc1313e7", - "Rev": "c1313e76341b18456212c5645d1daa7f132ac50e" + "Comment": "1.0.0-161-g3303647", + "Rev": "3303647209557312e5db51450ea8bbdef56d5176" }, { "ImportPath": "github.com/shirou/gopsutil/cpu", - "Comment": "1.0.0-153-gc1313e7", - "Rev": "c1313e76341b18456212c5645d1daa7f132ac50e" + "Comment": "1.0.0-161-g3303647", + "Rev": "3303647209557312e5db51450ea8bbdef56d5176" }, { "ImportPath": "github.com/shirou/gopsutil/disk", - "Comment": "1.0.0-153-gc1313e7", - "Rev": "c1313e76341b18456212c5645d1daa7f132ac50e" + "Comment": "1.0.0-161-g3303647", + "Rev": "3303647209557312e5db51450ea8bbdef56d5176" }, { "ImportPath": "github.com/shirou/gopsutil/docker", - "Comment": "1.0.0-153-gc1313e7", - "Rev": "c1313e76341b18456212c5645d1daa7f132ac50e" + "Comment": "1.0.0-161-g3303647", + "Rev": "3303647209557312e5db51450ea8bbdef56d5176" }, { "ImportPath": "github.com/shirou/gopsutil/load", - "Comment": "1.0.0-153-gc1313e7", - "Rev": "c1313e76341b18456212c5645d1daa7f132ac50e" + "Comment": "1.0.0-161-g3303647", + "Rev": "3303647209557312e5db51450ea8bbdef56d5176" }, { "ImportPath": "github.com/shirou/gopsutil/mem", - "Comment": "1.0.0-153-gc1313e7", - "Rev": "c1313e76341b18456212c5645d1daa7f132ac50e" + "Comment": "1.0.0-161-g3303647", + "Rev": "3303647209557312e5db51450ea8bbdef56d5176" }, { "ImportPath": "github.com/shirou/gopsutil/net", - "Comment": "1.0.0-153-gc1313e7", - "Rev": "c1313e76341b18456212c5645d1daa7f132ac50e" + "Comment": "1.0.0-161-g3303647", + "Rev": "3303647209557312e5db51450ea8bbdef56d5176" }, { "ImportPath": "github.com/streadway/amqp", diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/docker/docker_linux.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/docker/docker_linux.go index 1113e4cce..fd6df6d8b 100644 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/docker/docker_linux.go +++ b/Godeps/_workspace/src/github.com/shirou/gopsutil/docker/docker_linux.go @@ -4,6 +4,7 @@ package docker import ( "encoding/json" + "os" "os/exec" "path" "strconv" @@ -46,9 +47,13 @@ func CgroupCPU(containerid string, base string) (*cpu.CPUTimesStat, error) { if len(base) == 0 { base = "/sys/fs/cgroup/cpuacct/docker" } - path := path.Join(base, containerid, "cpuacct.stat") + statfile := path.Join(base, containerid, "cpuacct.stat") - lines, err := common.ReadLines(path) + if _, err := os.Stat(statfile); os.IsNotExist(err) { + statfile = path.Join("/sys/fs/cgroup/cpuacct/system.slice", "docker-" + containerid + ".scope", "cpuacct.stat") + } + + lines, err := common.ReadLines(statfile) if err != nil { return nil, err } @@ -84,12 +89,17 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) { if len(base) == 0 { base = "/sys/fs/cgroup/memory/docker" } - path := path.Join(base, containerid, "memory.stat") + statfile := path.Join(base, containerid, "memory.stat") + + if _, err := os.Stat(statfile); os.IsNotExist(err) { + statfile = path.Join("/sys/fs/cgroup/memory/system.slice", "docker-" + containerid + ".scope", "memory.stat") + } + // empty containerid means all cgroup if len(containerid) == 0 { containerid = "all" } - lines, err := common.ReadLines(path) + lines, err := common.ReadLines(statfile) if err != nil { return nil, err } diff --git a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go index d27f231e0..ccad5da90 100644 --- a/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go +++ b/Godeps/_workspace/src/github.com/shirou/gopsutil/mem/mem_linux.go @@ -13,6 +13,8 @@ import ( func VirtualMemory() (*VirtualMemoryStat, error) { filename := "/proc/meminfo" lines, _ := common.ReadLines(filename) + // flag if MemAvailable is in /proc/meminfo (kernel 3.14+) + memavail := false ret := &VirtualMemoryStat{} for _, line := range lines { @@ -33,6 +35,9 @@ func VirtualMemory() (*VirtualMemoryStat, error) { ret.Total = t * 1024 case "MemFree": ret.Free = t * 1024 + case "MemAvailable": + memavail = true + ret.Available = t * 1024 case "Buffers": ret.Buffers = t * 1024 case "Cached": @@ -43,7 +48,9 @@ func VirtualMemory() (*VirtualMemoryStat, error) { ret.Inactive = t * 1024 } } - ret.Available = ret.Free + ret.Buffers + ret.Cached + if !memavail { + ret.Available = ret.Free + ret.Buffers + ret.Cached + } ret.Used = ret.Total - ret.Free ret.UsedPercent = float64(ret.Total-ret.Available) / float64(ret.Total) * 100.0