From 470ae6548ec9c9e16d5b85320fef9e3f958185f2 Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Mon, 6 Apr 2015 17:21:43 -0700 Subject: [PATCH] Report that docker isn't available better in psutils --- plugins/system/ps/docker/docker.go | 4 ++++ plugins/system/ps/docker/docker_linux.go | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/system/ps/docker/docker.go b/plugins/system/ps/docker/docker.go index bc284f01b..5cd4c62c6 100644 --- a/plugins/system/ps/docker/docker.go +++ b/plugins/system/ps/docker/docker.go @@ -1,5 +1,9 @@ package docker +import "errors" + +var ErrNotAvailable = errors.New("docker not available") + type CgroupMemStat struct { ContainerID string `json:"container_id"` Cache uint64 `json:"cache"` diff --git a/plugins/system/ps/docker/docker_linux.go b/plugins/system/ps/docker/docker_linux.go index aee9aa35c..265ab8afc 100644 --- a/plugins/system/ps/docker/docker_linux.go +++ b/plugins/system/ps/docker/docker_linux.go @@ -16,14 +16,24 @@ import ( // GetDockerIDList returnes a list of DockerID. // This requires certain permission. func GetDockerIDList() ([]string, error) { - out, err := exec.Command("docker", "ps", "-q", "--no-trunc").Output() + path, err := exec.LookPath("docker") + if err != nil { + return nil, ErrNotAvailable + } + + out, err := exec.Command(path, "ps", "-q", "--no-trunc").Output() if err != nil { return []string{}, err } + lines := strings.Split(string(out), "\n") ret := make([]string, 0, len(lines)) for _, l := range lines { + if l == "" { + continue + } + ret = append(ret, l) }