Fix docker stats to make it work on centos 7.
This commit is contained in:
parent
3c7c8926fb
commit
da4cc57c5e
|
@ -4,6 +4,7 @@ package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -48,9 +49,13 @@ func CgroupCPU(containerid string, base string) (*cpu.CPUTimesStat, error) {
|
||||||
if len(base) == 0 {
|
if len(base) == 0 {
|
||||||
base = "/sys/fs/cgroup/cpuacct/docker"
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -86,12 +91,17 @@ func CgroupMem(containerid string, base string) (*CgroupMemStat, error) {
|
||||||
if len(base) == 0 {
|
if len(base) == 0 {
|
||||||
base = "/sys/fs/cgroup/memory/docker"
|
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
|
// empty containerid means all cgroup
|
||||||
if len(containerid) == 0 {
|
if len(containerid) == 0 {
|
||||||
containerid = "all"
|
containerid = "all"
|
||||||
}
|
}
|
||||||
lines, err := common.ReadLines(path)
|
lines, err := common.ReadLines(statfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue