2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-11-30 23:34:01 +00:00
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
2015-12-14 22:43:00 +00:00
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
type StatsTask struct {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
Stat chan *runtime.Stat
|
|
|
|
Err chan error
|
2015-12-16 17:39:28 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) stats(t *StatsTask) error {
|
2016-02-11 22:36:32 +00:00
|
|
|
start := time.Now()
|
2016-02-17 18:55:54 +00:00
|
|
|
i, ok := s.containers[t.ID]
|
2015-12-14 22:43:00 +00:00
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
2016-02-11 22:36:32 +00:00
|
|
|
// TODO: use workers for this
|
|
|
|
go func() {
|
|
|
|
s, err := i.container.Stats()
|
|
|
|
if err != nil {
|
2016-02-17 18:55:54 +00:00
|
|
|
t.Err <- err
|
2016-02-11 22:36:32 +00:00
|
|
|
return
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
t.Err <- nil
|
|
|
|
t.Stat <- s
|
2016-02-11 22:36:32 +00:00
|
|
|
ContainerStatsTimer.UpdateSince(start)
|
|
|
|
}()
|
2016-02-17 18:55:54 +00:00
|
|
|
return nil
|
2015-12-16 17:39:28 +00:00
|
|
|
}
|