2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-11-30 23:34:01 +00:00
|
|
|
|
|
|
|
import "github.com/rcrowley/go-metrics"
|
|
|
|
|
|
|
|
var (
|
2015-12-10 20:30:04 +00:00
|
|
|
ContainerStartTimer = metrics.NewTimer()
|
|
|
|
ContainersCounter = metrics.NewCounter()
|
|
|
|
EventsCounter = metrics.NewCounter()
|
|
|
|
EventSubscriberCounter = metrics.NewCounter()
|
2015-11-30 23:34:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Metrics() map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
|
|
|
"container-start-time": ContainerStartTimer,
|
|
|
|
"containers": ContainersCounter,
|
2015-12-01 18:55:13 +00:00
|
|
|
"events": EventsCounter,
|
2015-12-10 20:30:04 +00:00
|
|
|
"events-subscribers": EventSubscriberCounter,
|
2015-11-30 23:34:01 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-14 22:43:00 +00:00
|
|
|
|
|
|
|
type StatsEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
|
|
|
type UnsubscribeStatsEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2015-12-16 17:39:28 +00:00
|
|
|
type StopStatsEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2015-12-14 22:43:00 +00:00
|
|
|
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
|
|
|
|
}
|
2015-12-16 17:39:28 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|