types.go 1.0 KB

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