1package stats 2 3import ( 4 "bufio" 5 "sync" 6 "time" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/container" 10 "github.com/docker/docker/pkg/pubsub" 11) 12 13type supervisor interface { 14 // GetContainerStats collects all the stats related to a container 15 GetContainerStats(container *container.Container) (*types.StatsJSON, error) 16} 17 18// NewCollector creates a stats collector that will poll the supervisor with the specified interval 19func NewCollector(supervisor supervisor, interval time.Duration) *Collector { 20 s := &Collector{ 21 interval: interval, 22 supervisor: supervisor, 23 publishers: make(map[*container.Container]*pubsub.Publisher), 24 bufReader: bufio.NewReaderSize(nil, 128), 25 } 26 27 platformNewStatsCollector(s) 28 29 return s 30} 31 32// Collector manages and provides container resource stats 33type Collector struct { 34 m sync.Mutex 35 supervisor supervisor 36 interval time.Duration 37 publishers map[*container.Container]*pubsub.Publisher 38 bufReader *bufio.Reader 39 40 // The following fields are not set on Windows currently. 41 clockTicksPerSecond uint64 42} 43