moby/daemon/stats_collector.go
Sebastiaan van Stijn 6a516acb2e
pkg/system: move memory-info types to pkg/systeminfo
These types and functions are more closely related to the functionality
provided by pkg/systeminfo, and used in conjunction with the other functions
in that package, so moving them there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-12-21 10:53:45 +01:00

26 lines
782 B
Go

package daemon // import "github.com/docker/docker/daemon"
import (
"runtime"
"time"
"github.com/docker/docker/daemon/stats"
"github.com/docker/docker/pkg/sysinfo"
)
// newStatsCollector returns a new statsCollector that collections
// stats for a registered container at the specified interval.
// The collector allows non-running containers to be added
// and will start processing stats when they are started.
func (daemon *Daemon) newStatsCollector(interval time.Duration) *stats.Collector {
// FIXME(vdemeester) move this elsewhere
if runtime.GOOS == "linux" {
meminfo, err := sysinfo.ReadMemInfo()
if err == nil && meminfo.MemTotal > 0 {
daemon.machineMemory = uint64(meminfo.MemTotal)
}
}
s := stats.NewCollector(daemon, interval)
go s.Run()
return s
}