Clean up docker root dir

This commit is contained in:
Tim St. Clair 2016-05-06 19:31:36 -07:00
parent 4c506006f2
commit d1868287db
2 changed files with 23 additions and 18 deletions

View File

@ -26,11 +26,11 @@ import (
var (
dockerClient *dclient.Client
dockerClientErr error
once sync.Once
dockerClientOnce sync.Once
)
func Client() (*dclient.Client, error) {
once.Do(func() {
dockerClientOnce.Do(func() {
dockerClient, dockerClientErr = dclient.NewClient(*ArgDockerEndpoint, "", nil, nil)
})
return dockerClient, dockerClientErr

View File

@ -20,6 +20,7 @@ import (
"path"
"regexp"
"strings"
"sync"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/container/libcontainer"
@ -34,12 +35,7 @@ import (
var ArgDockerEndpoint = flag.String("docker", "unix:///var/run/docker.sock", "docker endpoint")
// The namespace under which Docker aliases are unique.
var DockerNamespace = "docker"
// Basepath to all container specific information that libcontainer stores.
// TODO: Deprecate this flag
var dockerRootDir = flag.String("docker_root", "/var/lib/docker", "Absolute path to the Docker state root directory (default: /var/lib/docker)")
var dockerRunDir = flag.String("docker_run", "/var/run/docker", "Absolute path to the Docker run directory (default: /var/run/docker)")
const DockerNamespace = "docker"
// Regexp that identifies docker cgroups, containers started with
// --cgroup-parent have another prefix than 'docker'
@ -47,12 +43,25 @@ var dockerCgroupRegexp = regexp.MustCompile(`([a-z0-9]{64})`)
var dockerEnvWhitelist = flag.String("docker_env_metadata_whitelist", "", "a comma-separated list of environment variable keys that needs to be collected for docker containers")
const (
dockerRootDirKey = "Root Dir"
var (
// Basepath to all container specific information that libcontainer stores.
dockerRootDir string
dockerRootDirFlag = flag.String("docker_root", "/var/lib/docker", "DEPRECATED: docker root is read from docker info (this is a fallback, default: /var/lib/docker)")
dockerRootDirOnce sync.Once
)
func RootDir() string {
return *dockerRootDir
dockerRootDirOnce.Do(func() {
status, err := Status()
if err == nil && status.RootDir != "" {
dockerRootDir = status.RootDir
} else {
dockerRootDir = *dockerRootDirFlag
}
})
return dockerRootDir
}
type storageDriver string
@ -172,10 +181,6 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
// Version already validated above, assume no error here.
dockerVersion, _ := parseDockerVersion(dockerInfo.ServerVersion)
storageDir := dockerInfo.DockerRootDir
if storageDir == "" {
storageDir = *dockerRootDir
}
cgroupSubsystems, err := libcontainer.GetCgroupSubsystems()
if err != nil {
return fmt.Errorf("failed to get cgroup subsystems: %v", err)
@ -189,7 +194,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
fsInfo: fsInfo,
machineInfoFactory: factory,
storageDriver: storageDriver(dockerInfo.Driver),
storageDir: storageDir,
storageDir: RootDir(),
ignoreMetrics: ignoreMetrics,
}