Merge branch 'master' into git_ignore
This commit is contained in:
commit
357cb54f15
@ -17,6 +17,7 @@ package docker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ func Status() (v1.DockerStatus, error) {
|
|||||||
|
|
||||||
out := v1.DockerStatus{}
|
out := v1.DockerStatus{}
|
||||||
out.Version = VersionString()
|
out.Version = VersionString()
|
||||||
|
out.APIVersion = APIVersionString()
|
||||||
out.KernelVersion = machine.KernelVersion()
|
out.KernelVersion = machine.KernelVersion()
|
||||||
out.OS = dockerInfo.OperatingSystem
|
out.OS = dockerInfo.OperatingSystem
|
||||||
out.Hostname = dockerInfo.Name
|
out.Hostname = dockerInfo.Name
|
||||||
@ -105,7 +107,7 @@ func ValidateInfo() (*dockertypes.Info, error) {
|
|||||||
}
|
}
|
||||||
dockerInfo.ServerVersion = version.Version
|
dockerInfo.ServerVersion = version.Version
|
||||||
}
|
}
|
||||||
version, err := parseDockerVersion(dockerInfo.ServerVersion)
|
version, err := parseVersion(dockerInfo.ServerVersion, version_re, 3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -129,7 +131,11 @@ func ValidateInfo() (*dockertypes.Info, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Version() ([]int, error) {
|
func Version() ([]int, error) {
|
||||||
return parseDockerVersion(VersionString())
|
return parseVersion(VersionString(), version_re, 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
func APIVersion() ([]int, error) {
|
||||||
|
return parseVersion(APIVersionString(), apiversion_re, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func VersionString() string {
|
func VersionString() string {
|
||||||
@ -144,18 +150,29 @@ func VersionString() string {
|
|||||||
return docker_version
|
return docker_version
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: switch to a semantic versioning library.
|
func APIVersionString() string {
|
||||||
func parseDockerVersion(full_version_string string) ([]int, error) {
|
docker_api_version := "Unknown"
|
||||||
matches := version_re.FindAllStringSubmatch(full_version_string, -1)
|
client, err := Client()
|
||||||
|
if err == nil {
|
||||||
|
version, err := client.ServerVersion(context.Background())
|
||||||
|
if err == nil {
|
||||||
|
docker_api_version = version.APIVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return docker_api_version
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseVersion(version_string string, regex *regexp.Regexp, length int) ([]int, error) {
|
||||||
|
matches := regex.FindAllStringSubmatch(version_string, -1)
|
||||||
if len(matches) != 1 {
|
if len(matches) != 1 {
|
||||||
return nil, fmt.Errorf("version string \"%v\" doesn't match expected regular expression: \"%v\"", full_version_string, version_regexp_string)
|
return nil, fmt.Errorf("version string \"%v\" doesn't match expected regular expression: \"%v\"", version_string, regex.String())
|
||||||
}
|
}
|
||||||
version_string_array := matches[0][1:]
|
version_string_array := matches[0][1:]
|
||||||
version_array := make([]int, 3)
|
version_array := make([]int, length)
|
||||||
for index, version_string := range version_string_array {
|
for index, version_str := range version_string_array {
|
||||||
version, err := strconv.Atoi(version_string)
|
version, err := strconv.Atoi(version_str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error while parsing \"%v\" in \"%v\"", version_string, full_version_string)
|
return nil, fmt.Errorf("error while parsing \"%v\" in \"%v\"", version_str, version_string)
|
||||||
}
|
}
|
||||||
version_array[index] = version
|
version_array[index] = version
|
||||||
}
|
}
|
||||||
|
51
container/docker/docker_test.go
Normal file
51
container/docker/docker_test.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright 2017 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.
|
||||||
|
|
||||||
|
package docker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"regexp"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseDockerAPIVersion(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
version string
|
||||||
|
regex *regexp.Regexp
|
||||||
|
length int
|
||||||
|
expected []int
|
||||||
|
expectedError string
|
||||||
|
}{
|
||||||
|
{"17.03.0", version_re, 3, []int{17, 03, 0}, ""},
|
||||||
|
{"17.a3.0", version_re, 3, []int{}, `version string "17.a3.0" doesn't match expected regular expression: "(\d+)\.(\d+)\.(\d+)"`},
|
||||||
|
{"1.20", apiversion_re, 2, []int{1, 20}, ""},
|
||||||
|
{"1.a", apiversion_re, 2, []int{}, `version string "1.a" doesn't match expected regular expression: "(\d+)\.(\d+)"`},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
actual, err := parseVersion(test.version, test.regex, test.length)
|
||||||
|
if err != nil {
|
||||||
|
if len(test.expectedError) == 0 {
|
||||||
|
t.Errorf("%s: expected no error, got %v", test.version, err)
|
||||||
|
} else if err.Error() != test.expectedError {
|
||||||
|
t.Errorf("%s: expected error %v, got %v", test.version, test.expectedError, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !reflect.DeepEqual(actual, test.expected) {
|
||||||
|
t.Errorf("%s: expected array %v, got %v", test.version, test.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -103,6 +103,8 @@ type dockerFactory struct {
|
|||||||
|
|
||||||
dockerVersion []int
|
dockerVersion []int
|
||||||
|
|
||||||
|
dockerAPIVersion []int
|
||||||
|
|
||||||
ignoreMetrics container.MetricSet
|
ignoreMetrics container.MetricSet
|
||||||
|
|
||||||
thinPoolWatcher *devicemapper.ThinPoolWatcher
|
thinPoolWatcher *devicemapper.ThinPoolWatcher
|
||||||
@ -185,8 +187,10 @@ func (self *dockerFactory) DebugInfo() map[string][]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version_regexp_string = `(\d+)\.(\d+)\.(\d+)`
|
version_regexp_string = `(\d+)\.(\d+)\.(\d+)`
|
||||||
version_re = regexp.MustCompile(version_regexp_string)
|
version_re = regexp.MustCompile(version_regexp_string)
|
||||||
|
apiversion_regexp_string = `(\d+)\.(\d+)`
|
||||||
|
apiversion_re = regexp.MustCompile(apiversion_regexp_string)
|
||||||
)
|
)
|
||||||
|
|
||||||
func startThinPoolWatcher(dockerInfo *dockertypes.Info) (*devicemapper.ThinPoolWatcher, error) {
|
func startThinPoolWatcher(dockerInfo *dockertypes.Info) (*devicemapper.ThinPoolWatcher, error) {
|
||||||
@ -310,7 +314,9 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Version already validated above, assume no error here.
|
// Version already validated above, assume no error here.
|
||||||
dockerVersion, _ := parseDockerVersion(dockerInfo.ServerVersion)
|
dockerVersion, _ := parseVersion(dockerInfo.ServerVersion, version_re, 3)
|
||||||
|
|
||||||
|
dockerAPIVersion, _ := APIVersion()
|
||||||
|
|
||||||
cgroupSubsystems, err := libcontainer.GetCgroupSubsystems()
|
cgroupSubsystems, err := libcontainer.GetCgroupSubsystems()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -338,6 +344,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
|
|||||||
cgroupSubsystems: cgroupSubsystems,
|
cgroupSubsystems: cgroupSubsystems,
|
||||||
client: client,
|
client: client,
|
||||||
dockerVersion: dockerVersion,
|
dockerVersion: dockerVersion,
|
||||||
|
dockerAPIVersion: dockerAPIVersion,
|
||||||
fsInfo: fsInfo,
|
fsInfo: fsInfo,
|
||||||
machineInfoFactory: factory,
|
machineInfoFactory: factory,
|
||||||
storageDriver: storageDriver(dockerInfo.Driver),
|
storageDriver: storageDriver(dockerInfo.Driver),
|
||||||
|
@ -18,6 +18,10 @@ sudo docker run \
|
|||||||
|
|
||||||
cAdvisor is now running (in the background) on `http://localhost:8080/`. The setup includes directories with Docker state cAdvisor needs to observe.
|
cAdvisor is now running (in the background) on `http://localhost:8080/`. The setup includes directories with Docker state cAdvisor needs to observe.
|
||||||
|
|
||||||
|
**Note**: If docker daemon is running with [user namespace enabled](https://docs.docker.com/engine/reference/commandline/dockerd/#starting-the-daemon-with-user-namespaces-enabled),
|
||||||
|
You need to add `--userns=host` option in order for cAdvisor to monitor Docker containers,
|
||||||
|
otherwise cAdvisor can not connect to docker daemon.
|
||||||
|
|
||||||
## Latest Canary
|
## Latest Canary
|
||||||
|
|
||||||
The latest cAdvisor canary release is continuously built from HEAD and available
|
The latest cAdvisor canary release is continuously built from HEAD and available
|
||||||
|
@ -17,6 +17,7 @@ package v1
|
|||||||
|
|
||||||
type DockerStatus struct {
|
type DockerStatus struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
APIVersion string `json:"api_version"`
|
||||||
KernelVersion string `json:"kernel_version"`
|
KernelVersion string `json:"kernel_version"`
|
||||||
OS string `json:"os"`
|
OS string `json:"os"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
|
@ -196,6 +196,9 @@ type VersionInfo struct {
|
|||||||
// Docker version.
|
// Docker version.
|
||||||
DockerVersion string `json:"docker_version"`
|
DockerVersion string `json:"docker_version"`
|
||||||
|
|
||||||
|
// Docker API Version
|
||||||
|
DockerAPIVersion string `json:"docker_api_version"`
|
||||||
|
|
||||||
// cAdvisor version.
|
// cAdvisor version.
|
||||||
CadvisorVersion string `json:"cadvisor_version"`
|
CadvisorVersion string `json:"cadvisor_version"`
|
||||||
// cAdvisor git revision.
|
// cAdvisor git revision.
|
||||||
|
@ -31,6 +31,9 @@ type Attributes struct {
|
|||||||
// Docker version.
|
// Docker version.
|
||||||
DockerVersion string `json:"docker_version"`
|
DockerVersion string `json:"docker_version"`
|
||||||
|
|
||||||
|
// Docker API version.
|
||||||
|
DockerAPIVersion string `json:"docker_api_version"`
|
||||||
|
|
||||||
// cAdvisor version.
|
// cAdvisor version.
|
||||||
CadvisorVersion string `json:"cadvisor_version"`
|
CadvisorVersion string `json:"cadvisor_version"`
|
||||||
|
|
||||||
@ -74,6 +77,7 @@ func GetAttributes(mi *v1.MachineInfo, vi *v1.VersionInfo) Attributes {
|
|||||||
KernelVersion: vi.KernelVersion,
|
KernelVersion: vi.KernelVersion,
|
||||||
ContainerOsVersion: vi.ContainerOsVersion,
|
ContainerOsVersion: vi.ContainerOsVersion,
|
||||||
DockerVersion: vi.DockerVersion,
|
DockerVersion: vi.DockerVersion,
|
||||||
|
DockerAPIVersion: vi.DockerAPIVersion,
|
||||||
CadvisorVersion: vi.CadvisorVersion,
|
CadvisorVersion: vi.CadvisorVersion,
|
||||||
NumCores: mi.NumCores,
|
NumCores: mi.NumCores,
|
||||||
CpuFrequency: mi.CpuFrequency,
|
CpuFrequency: mi.CpuFrequency,
|
||||||
|
@ -1255,11 +1255,13 @@ func getVersionInfo() (*info.VersionInfo, error) {
|
|||||||
kernel_version := machine.KernelVersion()
|
kernel_version := machine.KernelVersion()
|
||||||
container_os := machine.ContainerOsVersion()
|
container_os := machine.ContainerOsVersion()
|
||||||
docker_version := docker.VersionString()
|
docker_version := docker.VersionString()
|
||||||
|
docker_api_version := docker.APIVersionString()
|
||||||
|
|
||||||
return &info.VersionInfo{
|
return &info.VersionInfo{
|
||||||
KernelVersion: kernel_version,
|
KernelVersion: kernel_version,
|
||||||
ContainerOsVersion: container_os,
|
ContainerOsVersion: container_os,
|
||||||
DockerVersion: docker_version,
|
DockerVersion: docker_version,
|
||||||
|
DockerAPIVersion: docker_api_version,
|
||||||
CadvisorVersion: version.Info["version"],
|
CadvisorVersion: version.Info["version"],
|
||||||
CadvisorRevision: version.Info["revision"],
|
CadvisorRevision: version.Info["revision"],
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -40,6 +40,7 @@ func toStatusKV(status info.DockerStatus) ([]keyVal, []keyVal) {
|
|||||||
}
|
}
|
||||||
return []keyVal{
|
return []keyVal{
|
||||||
{Key: "Docker Version", Value: status.Version},
|
{Key: "Docker Version", Value: status.Version},
|
||||||
|
{Key: "Docker API Version", Value: status.APIVersion},
|
||||||
{Key: "Kernel Version", Value: status.KernelVersion},
|
{Key: "Kernel Version", Value: status.KernelVersion},
|
||||||
{Key: "OS Version", Value: status.OS},
|
{Key: "OS Version", Value: status.OS},
|
||||||
{Key: "Host Name", Value: status.Hostname},
|
{Key: "Host Name", Value: status.Hostname},
|
||||||
|
Loading…
Reference in New Issue
Block a user