Move supervisor to it's own package
It allows to keep main namespace cleaner Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
b296d50493
commit
69f8f566a2
24 changed files with 61 additions and 59 deletions
58
supervisor/stats.go
Normal file
58
supervisor/stats.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package supervisor
|
||||
|
||||
import "github.com/rcrowley/go-metrics"
|
||||
|
||||
var (
|
||||
ContainerStartTimer = metrics.NewTimer()
|
||||
ContainersCounter = metrics.NewCounter()
|
||||
EventsCounter = metrics.NewCounter()
|
||||
EventSubscriberCounter = metrics.NewCounter()
|
||||
)
|
||||
|
||||
func Metrics() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"container-start-time": ContainerStartTimer,
|
||||
"containers": ContainersCounter,
|
||||
"events": EventsCounter,
|
||||
"events-subscribers": EventSubscriberCounter,
|
||||
}
|
||||
}
|
||||
|
||||
type StatsEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
type UnsubscribeStatsEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
type StopStatsEvent struct {
|
||||
s *Supervisor
|
||||
}
|
||||
|
||||
func (h *StatsEvent) Handle(e *Event) error {
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue