Report that docker isn't available better in psutils
This commit is contained in:
parent
da3aeca720
commit
470ae6548e
|
@ -1,5 +1,9 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var ErrNotAvailable = errors.New("docker not available")
|
||||||
|
|
||||||
type CgroupMemStat struct {
|
type CgroupMemStat struct {
|
||||||
ContainerID string `json:"container_id"`
|
ContainerID string `json:"container_id"`
|
||||||
Cache uint64 `json:"cache"`
|
Cache uint64 `json:"cache"`
|
||||||
|
|
|
@ -16,14 +16,24 @@ import (
|
||||||
// GetDockerIDList returnes a list of DockerID.
|
// GetDockerIDList returnes a list of DockerID.
|
||||||
// This requires certain permission.
|
// This requires certain permission.
|
||||||
func GetDockerIDList() ([]string, error) {
|
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 {
|
if err != nil {
|
||||||
return []string{}, err
|
return []string{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(string(out), "\n")
|
lines := strings.Split(string(out), "\n")
|
||||||
ret := make([]string, 0, len(lines))
|
ret := make([]string, 0, len(lines))
|
||||||
|
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
|
if l == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
ret = append(ret, l)
|
ret = append(ret, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue