github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/stats_collector.go (about)

     1  package daemon // import "github.com/docker/docker/daemon"
     2  
     3  import (
     4  	"runtime"
     5  	"time"
     6  
     7  	"github.com/docker/docker/daemon/stats"
     8  	"github.com/docker/docker/pkg/system"
     9  )
    10  
    11  // newStatsCollector returns a new statsCollector that collections
    12  // stats for a registered container at the specified interval.
    13  // The collector allows non-running containers to be added
    14  // and will start processing stats when they are started.
    15  func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector {
    16  	// FIXME(vdemeester) move this elsewhere
    17  	if runtime.GOOS == "linux" {
    18  		meminfo, err := system.ReadMemInfo()
    19  		if err == nil && meminfo.MemTotal > 0 {
    20  			daemon.machineMemory = uint64(meminfo.MemTotal)
    21  		}
    22  	}
    23  	s := stats.NewCollector(daemon, interval)
    24  	go s.Run()
    25  	return s
    26  }