Skip to content

Commit

Permalink
bump(github.com/google/cadvisor): bdd574b
Browse files Browse the repository at this point in the history
  • Loading branch information
dchen1107 committed Jul 31, 2014
1 parent 2dc94e4 commit 76ec7ac
Show file tree
Hide file tree
Showing 41 changed files with 1,854 additions and 611 deletions.
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (kl *Kubelet) runContainer(pod *Pod, container *api.Container, podVolumes v
ExposedPorts: exposedPorts,
Hostname: container.Name,
Image: container.Image,
Memory: int64(container.Memory),
Memory: uint64(container.Memory),
CpuShares: int64(milliCPUToShares(container.CPU)),
Volumes: volumes,
WorkingDir: container.WorkingDir,
Expand Down
15 changes: 15 additions & 0 deletions third_party/src/github.com/google/cadvisor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 0.2.1 (2014-07-25)
- Handle old Docker versions.
- UI fixes and other bugfixes.

## 0.2.0 (2014-07-24)
- Added network stats to the UI.
- Added support for CoreOS and RHEL.
- Bugfixes and reliability fixes.

## 0.1.4 (2014-07-22)
- Add network statistics to REST API.
- Add "raw" driver to handle non-Docker containers.
- Remove lmctfy in favor of the raw driver.
- Bugfixes for Docker containers and logging.

## 0.1.3 (2014-07-14)
- Add support for systemd systems.
- Fixes for UI with InfluxDB storage driver.
Expand Down
7 changes: 4 additions & 3 deletions third_party/src/github.com/google/cadvisor/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cAdvisor

cAdvisor (Container Advisor) provides container users an understanding of the resource usage and performance characteristics of their running containers. It is a running daemon that collects, aggregates, processes, and exports information about running containers. Specifically, for each container it keeps resource isolation parameters, historical resource usage, and histograms of complete historical resource usage. This data is exported by container and machine-wide.
cAdvisor (Container Advisor) provides container users an understanding of the resource usage and performance characteristics of their running containers. It is a running daemon that collects, aggregates, processes, and exports information about running containers. Specifically, for each container it keeps resource isolation parameters, historical resource usage, histograms of complete historical resource usage and network statistics. This data is exported by container and machine-wide.

cAdvisor currently supports lmctfy containers as well as Docker containers (those that use the default libcontainer execdriver). Other container backends can also be added. cAdvisor's container abstraction is based on lmctfy's so containers are inherently nested hierarchically.

Expand All @@ -13,11 +13,12 @@ To quickly tryout cAdvisor on your machine with Docker (version 0.11 or above),
```
sudo docker run \
--volume=/var/run:/var/run:rw \
--volume=/sys/fs/cgroup/:/sys/fs/cgroup:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--publish=8080:8080 \
--detach=true \
google/cadvisor
--name=cadvisor \
google/cadvisor:latest
```

cAdvisor is now running (in the background) on `http://localhost:8080`. The setup includes directories with Docker state cAdvisor needs to observe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package inference
package interference

import "github.com/google/cadvisor/info"

Expand Down
5 changes: 5 additions & 0 deletions third_party/src/github.com/google/cadvisor/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func HandleRequest(m manager.Manager, w http.ResponseWriter, r *http.Request) er
log.Printf("Api - Container(%s)", containerName)

var query info.ContainerInfoRequest

// If a user does not specify number of stats/samples he wants,
// it's 64 by default
query.NumStats = 64
query.NumSamples = 64
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&query)
if err != nil && err != io.EOF {
Expand Down
36 changes: 11 additions & 25 deletions third_party/src/github.com/google/cadvisor/cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ import (

"github.com/google/cadvisor/api"
"github.com/google/cadvisor/container/docker"
"github.com/google/cadvisor/container/lmctfy"
"github.com/google/cadvisor/container/raw"
"github.com/google/cadvisor/info"
"github.com/google/cadvisor/manager"
"github.com/google/cadvisor/pages"
"github.com/google/cadvisor/pages/static"
)

var argPort = flag.Int("port", 8080, "port to listen")
var argAllowLmctfy = flag.Bool("allow_lmctfy", true, "whether to allow lmctfy as a container handler")

var argDbDriver = flag.String("storage_driver", "memory", "storage driver to use. Options are: memory (default) and influxdb")

Expand All @@ -47,30 +46,14 @@ func main() {
log.Fatalf("Failed to create a Container Manager: %s", err)
}

// Register lmctfy for the root if allowed and available.
registeredRoot := false
if *argAllowLmctfy {
if err := lmctfy.Register("/"); err != nil {
log.Printf("lmctfy registration failed: %v.", err)
log.Print("Running in docker only mode.")
} else {
registeredRoot = true
}
}

// Register Docker for root if we were unable to register lmctfy.
if !registeredRoot {
if err := docker.Register(containerManager, "/"); err != nil {
log.Printf("Docker registration failed: %v.", err)
log.Fatalf("Unable to continue without root handler.")
}
// Register Docker.
if err := docker.Register(containerManager); err != nil {
log.Printf("Docker registration failed: %v.", err)
}

// Register Docker for all Docker containers.
if err := docker.Register(containerManager, "/docker"); err != nil {
// Ignore this error because we should work with lmctfy only
log.Printf("Docker registration failed: %v.", err)
log.Print("Running in lmctfy only mode.")
// Register the raw driver.
if err := raw.Register(containerManager); err != nil {
log.Fatalf("raw registration failed: %v.", err)
}

// Handler for static content.
Expand Down Expand Up @@ -100,11 +83,14 @@ func main() {
}
})

go containerManager.Start()
go func() {
log.Fatal(containerManager.Start())
}()

log.Printf("Starting cAdvisor version: %q", info.VERSION)
log.Print("About to serve on port ", *argPort)

addr := fmt.Sprintf(":%v", *argPort)

log.Fatal(http.ListenAndServe(addr, nil))
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ package docker
import (
"flag"
"fmt"
"log"
"regexp"
"strconv"
"strings"

"github.com/docker/libcontainer/cgroups/systemd"
"github.com/fsouza/go-dockerclient"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/info"
)

var ArgDockerEndpoint = flag.String("docker", "unix:///var/run/docker.sock", "docker endpoint")

type dockerFactory struct {
machineInfoFactory info.MachineInfoFactory

// Whether this system is using systemd.
useSystemd bool

client *docker.Client
}

func (self *dockerFactory) String() string {
Expand All @@ -44,10 +53,42 @@ func (self *dockerFactory) NewContainerHandler(name string) (handler container.C
client,
name,
self.machineInfoFactory,
self.useSystemd,
)
return
}

// Docker handles all containers under /docker
// TODO(vishh): Change the CanHandle interface to be able to return errors.
func (self *dockerFactory) CanHandle(name string) bool {
// In systemd systems the containers are: /system.slice/docker-{ID}
if self.useSystemd {
if !strings.HasPrefix(name, "/system.slice/docker-") {
return false
}
} else if name == "/" {
return false
} else if name == "/docker" {
// We need the docker driver to handle /docker. Otherwise the aggregation at the API level will break.
return true
} else if !strings.HasPrefix(name, "/docker/") {
return false
}
// Check if the container is known to docker and it is active.
_, id, err := libcontainer.SplitName(name)
if err != nil {
return false
}
ctnr, err := self.client.InspectContainer(id)
// We assume that if Inspect fails then the container is not known to docker.
// TODO(vishh): Detect lxc containers and avoid handling them.
if err != nil || !ctnr.State.Running {
return false
}

return true
}

func parseDockerVersion(full_version_string string) ([]int, error) {
version_regexp_string := "(\\d+)\\.(\\d+)\\.(\\d+)"
version_re := regexp.MustCompile(version_regexp_string)
Expand All @@ -68,7 +109,7 @@ func parseDockerVersion(full_version_string string) ([]int, error) {
}

// Register root container before running this function!
func Register(factory info.MachineInfoFactory, paths ...string) error {
func Register(factory info.MachineInfoFactory) error {
client, err := docker.NewClient(*ArgDockerEndpoint)
if err != nil {
return fmt.Errorf("unable to communicate with docker daemon: %v", err)
Expand All @@ -92,12 +133,13 @@ func Register(factory info.MachineInfoFactory, paths ...string) error {
}
f := &dockerFactory{
machineInfoFactory: factory,
useSystemd: systemd.UseSystemd(),
client: client,
}
for _, p := range paths {
if p != "/" && p != "/docker" {
return fmt.Errorf("%v cannot be managed by docker", p)
}
container.RegisterContainerHandlerFactory(p, f)
if f.useSystemd {
log.Printf("System is using systemd")
}
log.Printf("Registering Docker factory")
container.RegisterContainerHandlerFactory(f)
return nil
}
Loading

0 comments on commit 76ec7ac

Please sign in to comment.