Merge pull request #1687 from weaveworks/1683-ignore-stopped-stats

eliminate stats log noise from stopped containers

Fixes #1683.
This commit is contained in:
Matthias Radestock
2016-07-18 14:39:12 +01:00
committed by GitHub

View File

@@ -185,7 +185,7 @@ func (c *container) StartGatheringStats() error {
}
go func() {
log.Infof("docker container: collecting stats for %s", c.container.ID)
log.Debugf("docker container: collecting stats for %s", c.container.ID)
req, err := http.NewRequest("GET", fmt.Sprintf("/containers/%s/stats", c.container.ID), nil)
if err != nil {
log.Errorf("docker container: %v", err)
@@ -221,20 +221,28 @@ func (c *container) StartGatheringStats() error {
c.Lock()
defer c.Unlock()
log.Infof("docker container: stopped collecting stats for %s", c.container.ID)
log.Debugf("docker container: stopped collecting stats for %s", c.container.ID)
c.statsConn = nil
}()
var stats docker.Stats
// Use a buffer since the codec library doesn't implicitly do it
bufReader := bufio.NewReader(resp.Body)
decoder := codec.NewDecoder(bufReader, &codec.JsonHandle{})
for err := decoder.Decode(&stats); err != io.EOF; err = decoder.Decode(&stats) {
if err != nil {
log.Errorf("docker container: error reading event for %s, did container stop? %v", c.container.ID, err)
return
for {
var stats docker.Stats
if err := decoder.Decode(&stats); err != nil {
if err == io.EOF {
break
}
// Unfortunately we typically get a different error
// than io.EOF. Yes, this is really the best we can do
// in go - https://github.com/golang/go/issues/4373
if opErr, ok := err.(*net.OpError); ok && opErr.Err.Error() == "use of closed network connection" {
break
}
log.Errorf("docker container: error reading event for %s: %v", c.container.ID, err)
break
}
c.Lock()
if c.numPending >= len(c.pendingStats) {
log.Warnf("docker container: dropping stats for %s", c.container.ID)
@@ -244,8 +252,6 @@ func (c *container) StartGatheringStats() error {
c.numPending++
}
c.Unlock()
stats = docker.Stats{}
}
}()