remove duplicate inspect, trigger refresh on "health_status" events

This commit is contained in:
Bradley Cicenas 2017-08-27 23:29:59 +00:00
parent 626d50d3e9
commit a1ebf3f90e

View File

@ -45,8 +45,11 @@ func (cm *Docker) watchEvents() {
if e.Type != "container" {
continue
}
switch e.Action {
case "start", "die", "pause", "unpause":
actionName := strings.Split(e.Action, ":")[0]
switch actionName {
case "start", "die", "pause", "unpause", "health_status":
log.Debugf("handling docker event: action=%s id=%s", e.Action, e.ID)
cm.needsRefresh <- e.ID
case "destroy":
@ -111,7 +114,6 @@ func (cm *Docker) refreshAll() {
c := cm.MustGet(i.ID)
c.SetMeta("name", shortName(i.Names[0]))
c.SetState(i.State)
cm.HealthCheck(i.ID)
cm.needsRefresh <- c.Id
}
}
@ -160,9 +162,6 @@ func (cm *Docker) All() (containers container.Containers) {
cm.lock.Lock()
for _, c := range cm.containers {
containers = append(containers, c)
cm.lock.Unlock()
cm.HealthCheck(c.Id)
cm.lock.Lock()
}
containers.Sort()
@ -175,9 +174,3 @@ func (cm *Docker) All() (containers container.Containers) {
func shortName(name string) string {
return strings.Replace(name, "/", "", 1)
}
func (cm *Docker) HealthCheck(id string){
insp := cm.inspect(id)
c := cm.MustGet(id)
c.SetMeta("health", insp.State.Health.Status)
}