Skip to content

Commit

Permalink
#224 Subscribe to only those events that we handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stokito committed Nov 19, 2020
1 parent 9b6520f commit bef3514
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions connector/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -19,7 +20,6 @@ import (
func init() { enabled["docker"] = NewDocker }

var actionToStatus = map[string]string{
"create": "created",
"start": "running",
"die": "exited",
"stop": "exited",
Expand Down Expand Up @@ -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_") {
Expand Down

0 comments on commit bef3514

Please sign in to comment.