parent
5a5d0575f5
commit
357e6a0f23
37
container/docker/client.go
Normal file
37
container/docker/client.go
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2015 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Handler for /validate content.
|
||||
// Validates cadvisor dependencies - kernel, os, docker setup.
|
||||
|
||||
package docker
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
dclient "github.com/fsouza/go-dockerclient"
|
||||
)
|
||||
|
||||
var (
|
||||
dockerClient *dclient.Client
|
||||
dockerClientErr error
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
func Client() (*dclient.Client, error) {
|
||||
once.Do(func() {
|
||||
dockerClient, dockerClientErr = dclient.NewClient(*ArgDockerEndpoint)
|
||||
})
|
||||
return dockerClient, dockerClientErr
|
||||
}
|
@ -101,7 +101,7 @@ func (self *dockerFactory) String() string {
|
||||
}
|
||||
|
||||
func (self *dockerFactory) NewContainerHandler(name string, inHostNamespace bool) (handler container.ContainerHandler, err error) {
|
||||
client, err := docker.NewClient(*ArgDockerEndpoint)
|
||||
client, err := Client()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -184,7 +184,7 @@ func parseDockerVersion(full_version_string string) ([]int, error) {
|
||||
|
||||
// Register root container before running this function!
|
||||
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo) error {
|
||||
client, err := docker.NewClient(*ArgDockerEndpoint)
|
||||
client, err := Client()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to communicate with docker daemon: %v", err)
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ func (self *dockerContainerHandler) Exists() bool {
|
||||
}
|
||||
|
||||
func DockerInfo() (map[string]string, error) {
|
||||
client, err := docker.NewClient(*ArgDockerEndpoint)
|
||||
client, err := Client()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to communicate with docker daemon: %v", err)
|
||||
}
|
||||
@ -347,7 +347,7 @@ func DockerInfo() (map[string]string, error) {
|
||||
}
|
||||
|
||||
func DockerImages() ([]docker.APIImages, error) {
|
||||
client, err := docker.NewClient(*ArgDockerEndpoint)
|
||||
client, err := Client()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to communicate with docker daemon: %v", err)
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
dclient "github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
"github.com/google/cadvisor/container/docker"
|
||||
"github.com/google/cadvisor/fs"
|
||||
@ -146,7 +145,7 @@ func getContainerOsVersion() string {
|
||||
|
||||
func getDockerVersion() string {
|
||||
docker_version := "Unknown"
|
||||
client, err := dclient.NewClient(*docker.ArgDockerEndpoint)
|
||||
client, err := docker.Client()
|
||||
if err == nil {
|
||||
version, err := client.Version()
|
||||
if err == nil {
|
||||
|
@ -19,15 +19,15 @@ package validate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/cadvisor/manager"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/google/cadvisor/manager"
|
||||
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
dclient "github.com/fsouza/go-dockerclient"
|
||||
"github.com/google/cadvisor/container/docker"
|
||||
"github.com/google/cadvisor/utils"
|
||||
)
|
||||
@ -185,7 +185,7 @@ func validateCgroups() (string, string) {
|
||||
}
|
||||
|
||||
func validateDockerInfo() (string, string) {
|
||||
client, err := dclient.NewClient(*docker.ArgDockerEndpoint)
|
||||
client, err := docker.Client()
|
||||
if err == nil {
|
||||
info, err := client.Info()
|
||||
if err == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user