Sfoglia il codice sorgente

Don't read CPU usage if there is no subscribers for stats

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Alexander Morozov 9 anni fa
parent
commit
c486a3a6dc
1 ha cambiato i file con 9 aggiunte e 6 eliminazioni
  1. 9 6
      daemon/stats_collector_unix.go

+ 9 - 6
daemon/stats_collector_unix.go

@@ -89,12 +89,6 @@ func (s *statsCollector) run() {
 	var pairs []publishersPair
 	var pairs []publishersPair
 
 
 	for range time.Tick(s.interval) {
 	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,
 		// it does not make sense in the first iteration,
 		// but saves allocations in further iterations
 		// but saves allocations in further iterations
 		pairs = pairs[:0]
 		pairs = pairs[:0]
@@ -105,6 +99,15 @@ func (s *statsCollector) run() {
 			pairs = append(pairs, publishersPair{container, publisher})
 			pairs = append(pairs, publishersPair{container, publisher})
 		}
 		}
 		s.m.Unlock()
 		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 {
 		for _, pair := range pairs {
 			stats, err := pair.container.stats()
 			stats, err := pair.container.stats()