Skip to content

Commit

Permalink
Don't read CPU usage if there is no subscribers for stats
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Morozov <[email protected]>
  • Loading branch information
LK4D4 committed Sep 8, 2015
1 parent a8d6b03 commit c486a3a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions daemon/stats_collector_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ func (s *statsCollector) run() {
var pairs []publishersPair

for range time.Tick(s.interval) {
systemUsage, err := s.getSystemCPUUsage()
if err != nil {
logrus.Errorf("collecting system cpu usage: %v", err)
continue
}

// it does not make sense in the first iteration,
// but saves allocations in further iterations
pairs = pairs[:0]
Expand All @@ -105,6 +99,15 @@ func (s *statsCollector) run() {
pairs = append(pairs, publishersPair{container, publisher})
}
s.m.Unlock()
if len(pairs) == 0 {
continue
}

systemUsage, err := s.getSystemCPUUsage()
if err != nil {
logrus.Errorf("collecting system cpu usage: %v", err)
continue
}

for _, pair := range pairs {
stats, err := pair.container.stats()
Expand Down

0 comments on commit c486a3a

Please sign in to comment.