Skip to content

Commit cd6618c

Browse files
committed
#224 Subscribe to only those events that we handling
1 parent 87b6ba3 commit cd6618c

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

connector/docker.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/bcicen/ctop/connector/manager"
88
"github.com/bcicen/ctop/container"
99
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/filters"
1011
"github.com/docker/docker/api/types/network"
1112
"github.com/docker/docker/client"
1213
"github.com/docker/go-connections/nat"
@@ -83,20 +84,22 @@ func (cm *Docker) Wait() struct{} { return <-cm.closed }
8384
func (cm *Docker) watchEvents() {
8485
log.Info("docker event listener starting")
8586
ctx := context.Background()
86-
87-
eventsOpts := types.EventsOptions{}
87+
filter := filters.NewArgs()
88+
filter.Add("type", "container")
89+
filter.Add("event", "health_status")
90+
filter.Add("event", "create")
91+
filter.Add("event", "destroy")
92+
filter.Add("event", "start")
93+
filter.Add("event", "die")
94+
filter.Add("event", "stop")
95+
filter.Add("event", "pause")
96+
filter.Add("event", "unpause")
97+
98+
eventsOpts := types.EventsOptions{Filters: filter}
8899
events, _ := cm.client.Events(ctx, eventsOpts)
89100

90101
for e := range events {
91-
if e.Type != "container" {
92-
continue
93-
}
94-
95102
actionName := e.Action
96-
// fast skip all exec_* events: exec_create, exec_start, exec_die
97-
if strings.HasPrefix(actionName, "exec_") {
98-
continue
99-
}
100103
// Action may have additional param i.e. "health_status: healthy"
101104
// We need to strip to have only action name
102105
sepIdx := strings.Index(actionName, ": ")

0 commit comments

Comments
 (0)