From bef351402c861a0ea6705e1f69f65f47e1bd90f1 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Thu, 19 Nov 2020 22:58:37 +0200 Subject: [PATCH] #224 Subscribe to only those events that we handling --- connector/docker.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/connector/docker.go b/connector/docker.go index e952ebe..c4507c6 100644 --- a/connector/docker.go +++ b/connector/docker.go @@ -7,6 +7,7 @@ import ( "github.com/bcicen/ctop/connector/manager" "github.com/bcicen/ctop/container" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" @@ -19,7 +20,6 @@ import ( func init() { enabled["docker"] = NewDocker } var actionToStatus = map[string]string{ - "create": "created", "start": "running", "die": "exited", "stop": "exited", @@ -85,14 +85,20 @@ func (cm *Docker) Wait() struct{} { return <-cm.closed } func (cm *Docker) watchEvents() { log.Info("docker event listener starting") ctx := context.Background() - eventsOpts := types.EventsOptions{} + filter := filters.NewArgs() + filter.Add("type", "container") + filter.Add("event", "health_status") + filter.Add("event", "create") + filter.Add("event", "destroy") + filter.Add("event", "start") + filter.Add("event", "die") + filter.Add("event", "stop") + filter.Add("event", "pause") + filter.Add("event", "unpause") + eventsOpts := types.EventsOptions{Filters: filter} events, _ := cm.client.Events(ctx, eventsOpts) for e := range events { - if e.Type != "container" { - continue - } - actionName := e.Action // fast skip all exec_* events: exec_create, exec_start, exec_die if strings.HasPrefix(actionName, "exec_") {