Report that docker isn't available better in psutils

This commit is contained in:
Evan Phoenix 2015-04-06 17:21:43 -07:00
parent da3aeca720
commit 470ae6548e
2 changed files with 15 additions and 1 deletions

View File

@ -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"`

View File

@ -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)
}