Avoid compiling cadvisor statically for the docker image by deriving the image from a stripped down busybox image.

Log failures encountered while dumping to influxdb
Handle critical failures in cadvisor gracefully without getting stuck.
This commit is contained in:
Vishnu Kannan 2014-09-19 07:41:11 +00:00
parent 7c59947ee8
commit 7ed645f004
5 changed files with 24 additions and 16 deletions

View File

@ -93,8 +93,9 @@ func main() {
defer glog.Flush() defer glog.Flush()
errChan := make(chan error)
go func() { go func() {
glog.Fatal(containerManager.Start()) errChan <- containerManager.Start()
}() }()
glog.Infof("Starting cAdvisor version: %q", info.VERSION) glog.Infof("Starting cAdvisor version: %q", info.VERSION)
@ -102,7 +103,13 @@ func main() {
addr := fmt.Sprintf(":%v", *argPort) addr := fmt.Sprintf(":%v", *argPort)
glog.Fatal(http.ListenAndServe(addr, nil)) go func() {
errChan <- http.ListenAndServe(addr, nil)
}()
select {
case err := <-errChan:
glog.Fatal(err)
}
} }
func setMaxProcs() { func setMaxProcs() {

View File

@ -1,11 +1,8 @@
FROM scratch FROM progrium/busybox
MAINTAINER dengnan@google.com vmarmol@google.com MAINTAINER dengnan@google.com vmarmol@google.com vishnuk@google.com
# NOTE: Run prepare.sh before building this Docker image.
# Grab cadvisor from the staging directory. # Grab cadvisor from the staging directory.
ADD cadvisor /usr/bin/cadvisor ADD cadvisor /usr/bin/cadvisor
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/usr/bin/cadvisor"] ENTRYPOINT ["/usr/bin/cadvisor"]
CMD ["-log_dir", "/"]

8
deploy/build.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
set -e
set -x
godep go build -a github.com/google/cadvisor
sudo docker build -t google/cadvisor:test .

View File

@ -1,7 +0,0 @@
#!/bin/bash
set -e
set -x
# Statically build cAdvisor from source and stage it.
godep go build -a --ldflags '-extldflags "-static"' github.com/google/cadvisor

View File

@ -19,6 +19,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"github.com/golang/glog"
"github.com/google/cadvisor/info" "github.com/google/cadvisor/info"
"github.com/google/cadvisor/storage" "github.com/google/cadvisor/storage"
) )
@ -104,7 +105,9 @@ func (self *InMemoryStorage) AddStats(ref info.ContainerReference, stats *info.C
// TODO(monnand): To deal with long delay write operations, we // TODO(monnand): To deal with long delay write operations, we
// may want to start a pool of goroutines to do write // may want to start a pool of goroutines to do write
// operations. // operations.
self.backend.AddStats(ref, stats) if err := self.backend.AddStats(ref, stats); err != nil {
glog.Error(err)
}
} }
return cstore.AddStats(stats) return cstore.AddStats(stats)
} }