2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-11-30 23:34:01 +00:00
|
|
|
|
2016-02-11 22:36:32 +00:00
|
|
|
import "time"
|
2015-12-14 22:43:00 +00:00
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
type StatsTask struct {
|
2015-12-16 17:39:28 +00:00
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
func (h *StatsTask) Handle(e *Task) error {
|
2016-02-11 22:36:32 +00:00
|
|
|
start := time.Now()
|
2015-12-14 22:43:00 +00:00
|
|
|
i, ok := h.s.containers[e.ID]
|
|
|
|
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 {
|
|
|
|
e.Err <- err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
e.Err <- nil
|
|
|
|
e.Stat <- s
|
|
|
|
ContainerStatsTimer.UpdateSince(start)
|
|
|
|
}()
|
|
|
|
return errDeferedResponse
|
2015-12-16 17:39:28 +00:00
|
|
|
}
|