2015-12-17 16:07:04 -08:00
|
|
|
package supervisor
|
2015-11-30 15:34:01 -08:00
|
|
|
|
2016-02-17 10:55:54 -08:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
2015-12-14 14:43:00 -08:00
|
|
|
|
2016-06-03 15:00:49 -07:00
|
|
|
// StatsTask holds needed parameters to retrieve a container statistics
|
2016-02-11 17:26:24 -08:00
|
|
|
type StatsTask struct {
|
2016-02-17 10:55:54 -08:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
Stat chan *runtime.Stat
|
2015-12-16 09:39:28 -08:00
|
|
|
}
|
|
|
|
|
2016-02-17 10:55:54 -08:00
|
|
|
func (s *Supervisor) stats(t *StatsTask) error {
|
2016-02-11 14:36:32 -08:00
|
|
|
start := time.Now()
|
2016-02-17 10:55:54 -08:00
|
|
|
i, ok := s.containers[t.ID]
|
2015-12-14 14:43:00 -08:00
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
2016-02-11 14:36:32 -08:00
|
|
|
// TODO: use workers for this
|
|
|
|
go func() {
|
|
|
|
s, err := i.container.Stats()
|
|
|
|
if err != nil {
|
2016-02-25 10:14:20 -08:00
|
|
|
t.ErrorCh() <- err
|
2016-02-11 14:36:32 -08:00
|
|
|
return
|
|
|
|
}
|
2016-02-25 10:14:20 -08:00
|
|
|
t.ErrorCh() <- nil
|
2016-02-17 10:55:54 -08:00
|
|
|
t.Stat <- s
|
2016-02-11 14:36:32 -08:00
|
|
|
ContainerStatsTimer.UpdateSince(start)
|
|
|
|
}()
|
2016-04-02 10:28:05 -07:00
|
|
|
return errDeferredResponse
|
2015-12-16 09:39:28 -08:00
|
|
|
}
|