Implement stats for containerd
This is a single endpoint that clients will poll Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
532697f32f
commit
bdeb87a090
11 changed files with 265 additions and 493 deletions
|
@ -1,40 +1,27 @@
|
|||
package supervisor
|
||||
|
||||
import "time"
|
||||
|
||||
type StatsEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
type UnsubscribeStatsEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
type StopStatsEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
func (h *StatsEvent) Handle(e *Event) error {
|
||||
start := time.Now()
|
||||
i, ok := h.s.containers[e.ID]
|
||||
if !ok {
|
||||
return ErrContainerNotFound
|
||||
}
|
||||
e.Stats = h.s.statsCollector.collect(i.container)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *UnsubscribeStatsEvent) Handle(e *Event) error {
|
||||
i, ok := h.s.containers[e.ID]
|
||||
if !ok {
|
||||
return ErrContainerNotFound
|
||||
}
|
||||
h.s.statsCollector.unsubscribe(i.container, e.Stats)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *StopStatsEvent) Handle(e *Event) error {
|
||||
i, ok := h.s.containers[e.ID]
|
||||
if !ok {
|
||||
return ErrContainerNotFound
|
||||
}
|
||||
h.s.statsCollector.stopCollection(i.container)
|
||||
return nil
|
||||
// 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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue