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-06-03 22:00:49 +00:00
|
|
|
// StatsTask holds needed parameters to retrieve a container statistics
|
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
|
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-25 18:14:20 +00:00
|
|
|
t.ErrorCh() <- err
|
2016-02-11 22:36:32 +00:00
|
|
|
return
|
|
|
|
}
|
2016-02-25 18:14:20 +00:00
|
|
|
t.ErrorCh() <- nil
|
2016-02-17 18:55:54 +00:00
|
|
|
t.Stat <- s
|
2016-02-11 22:36:32 +00:00
|
|
|
ContainerStatsTimer.UpdateSince(start)
|
|
|
|
}()
|
2016-04-02 17:28:05 +00:00
|
|
|
return errDeferredResponse
|
2015-12-16 17:39:28 +00:00
|
|
|
}
|