add a client to get container info from kubelet

This commit is contained in:
Nan Deng
2014-07-14 18:01:02 -07:00
committed by Nan Monnand Deng
parent c7d31fabbc
commit 6878f105c0
9 changed files with 333 additions and 33 deletions

View File

@@ -1,5 +1,9 @@
# Changelog
## 0.1.3 (2014-07-14)
- Add support for systemd systems.
- Fixes for UI with InfluxDB storage driver.
## 0.1.2 (2014-07-10)
- Added Storage Driver concept (flag: storage_driver), default is the in-memory driver
- Implemented InfluxDB storage driver

View File

@@ -110,32 +110,7 @@ func TestGetContainerInfo(t *testing.T) {
t.Fatal(err)
}
// We cannot use DeepEqual() to compare them directly,
// because json en/decoded time may have precision issues.
if !reflect.DeepEqual(returned.ContainerReference, cinfo.ContainerReference) {
t.Errorf("received unexpected container ref")
}
if !reflect.DeepEqual(returned.Subcontainers, cinfo.Subcontainers) {
t.Errorf("received unexpected subcontainers")
}
if !reflect.DeepEqual(returned.Spec, cinfo.Spec) {
t.Errorf("received unexpected spec")
}
if !reflect.DeepEqual(returned.StatsPercentiles, cinfo.StatsPercentiles) {
t.Errorf("received unexpected spec")
}
for i, expectedStats := range cinfo.Stats {
returnedStats := returned.Stats[i]
if !expectedStats.Eq(returnedStats) {
t.Errorf("received unexpected stats")
}
}
for i, expectedSample := range cinfo.Samples {
returnedSample := returned.Samples[i]
if !expectedSample.Eq(returnedSample) {
t.Errorf("received unexpected sample")
}
if !returned.Eq(cinfo) {
t.Error("received unexpected ContainerInfo")
}
}

View File

@@ -21,12 +21,14 @@ import (
"math"
"os"
"path"
"path/filepath"
"strings"
"time"
"github.com/docker/libcontainer"
"github.com/docker/libcontainer/cgroups"
"github.com/docker/libcontainer/cgroups/fs"
"github.com/docker/libcontainer/cgroups/systemd"
"github.com/fsouza/go-dockerclient"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/info"
@@ -98,8 +100,11 @@ func (self *dockerContainerHandler) splitName() (string, string, error) {
if nestedLevels > 0 {
// we are running inside a docker container
upperLevel := strings.Repeat("../../", nestedLevels)
//parent = strings.Join([]string{parent, upperLevel}, "/")
parent = fmt.Sprintf("%v%v", upperLevel, parent)
parent = filepath.Join(upperLevel, parent)
}
// Strip the last "/"
if parent[len(parent)-1] == '/' {
parent = parent[:len(parent)-1]
}
return parent, id, nil
}
@@ -237,7 +242,15 @@ func (self *dockerContainerHandler) GetStats() (stats *info.ContainerStats, err
Parent: parent,
Name: id,
}
s, err := fs.GetStats(cg)
// TODO(vmarmol): Use libcontainer's Stats() in the new API when that is ready.
// Use systemd paths if systemd is being used.
var s *cgroups.Stats
if systemd.UseSystemd() {
s, err = systemd.GetStats(cg)
} else {
s, err = fs.GetStats(cg)
}
if err != nil {
return
}

View File

@@ -2,7 +2,7 @@ FROM busybox:ubuntu-14.04
MAINTAINER kyurtsever@google.com dengnan@google.com vmarmol@google.com jason@swindle.me
# Get cAdvisor binaries.
ADD http://storage.googleapis.com/cadvisor-bin/cadvisor /usr/bin/cadvisor
ADD http://storage.googleapis.com/cadvisor-bin/cadvisor-0.1.3 /usr/bin/cadvisor
RUN chmod +x /usr/bin/cadvisor
EXPOSE 8080

View File

@@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y -q --no-install-recommends pkg-config l
# Get the lcmtfy and cAdvisor binaries.
ADD http://storage.googleapis.com/cadvisor-bin/lmctfy/lmctfy /usr/bin/lmctfy
ADD http://storage.googleapis.com/cadvisor-bin/lmctfy/libre2.so.0.0.0 /usr/lib/libre2.so.0
ADD http://storage.googleapis.com/cadvisor-bin/cadvisor-0.1.2 /usr/bin/cadvisor
ADD http://storage.googleapis.com/cadvisor-bin/cadvisor-0.1.3 /usr/bin/cadvisor
RUN chmod +x /usr/bin/lmctfy && chmod +x /usr/bin/cadvisor
EXPOSE 8080

View File

@@ -110,6 +110,52 @@ type ContainerInfo struct {
StatsPercentiles *ContainerStatsPercentiles `json:"stats_summary,omitempty"`
}
// ContainerInfo may be (un)marshaled by json or other en/decoder. In that
// case, the Timestamp field in each stats/sample may not be precisely
// en/decoded. This will lead to small but acceptable differences between a
// ContainerInfo and its encode-then-decode version. Eq() is used to compare
// two ContainerInfo accepting small difference (<10ms) of Time fields.
func (self *ContainerInfo) Eq(b *ContainerInfo) bool {
// If both self and b are nil, then Eq() returns true
if self == nil {
return b == nil
}
if b == nil {
return self == nil
}
// For fields other than time.Time, we will compare them precisely.
// This would require that any slice should have same order.
if !reflect.DeepEqual(self.ContainerReference, b.ContainerReference) {
return false
}
if !reflect.DeepEqual(self.Subcontainers, b.Subcontainers) {
return false
}
if !reflect.DeepEqual(self.Spec, b.Spec) {
return false
}
if !reflect.DeepEqual(self.StatsPercentiles, b.StatsPercentiles) {
return false
}
for i, expectedStats := range b.Stats {
selfStats := self.Stats[i]
if !expectedStats.Eq(selfStats) {
return false
}
}
for i, expectedSample := range b.Samples {
selfSample := self.Samples[i]
if !expectedSample.Eq(selfSample) {
return false
}
}
return true
}
func (self *ContainerInfo) StatsAfter(ref time.Time) []*ContainerStats {
n := len(self.Stats) + 1
for i, s := range self.Stats {

View File

@@ -15,4 +15,4 @@
package info
// Version of cAdvisor.
const VERSION = "0.1.2"
const VERSION = "0.1.3"