diff --git a/CHANGELOG.md b/CHANGELOG.md index 4973337c9..2cfaefda5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ will still be backwards compatible if only `url` is specified. - [#175](https://github.com/influxdb/telegraf/issues/175): Set write precision before gathering metrics - [#178](https://github.com/influxdb/telegraf/issues/178): redis plugin, multiple server thread hang bug - Fix net plugin on darwin +- [#84](https://github.com/influxdb/telegraf/issues/84): Fix docker plugin on CentOS. Thanks @neezgee! ## v0.1.8 [2015-09-04] diff --git a/plugins/system/ps/docker/docker_linux.go b/plugins/system/ps/docker/docker_linux.go index 51f3bc9ca..4c274af28 100644 --- a/plugins/system/ps/docker/docker_linux.go +++ b/plugins/system/ps/docker/docker_linux.go @@ -4,6 +4,7 @@ package docker import ( "encoding/json" + "os" "os/exec" "path" "strconv" @@ -48,9 +49,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 } @@ -86,12 +91,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 }