Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/stokito/events_filter'
Browse files Browse the repository at this point in the history
  • Loading branch information
bcicen committed Jun 11, 2021
2 parents 2b898fb + 77c9001 commit 9f8f38f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 82 deletions.
25 changes: 8 additions & 17 deletions connector/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,19 @@ func (cm *Docker) Wait() struct{} { return <-cm.closed }
func (cm *Docker) watchEvents() {
log.Info("docker event listener starting")
events := make(chan *api.APIEvents)
cm.client.AddEventListener(events)
opts := api.EventsOptions{Filters: map[string][]string{
"type": {"container"},
"event": {"create", "start", "health_status", "pause", "unpause", "stop", "die", "destroy"},
},
}
cm.client.AddEventListenerWithOptions(opts, events)

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_") {
continue
}
// Action may have additional param i.e. "health_status: healthy"
// We need to strip to have only action name
sepIdx := strings.Index(actionName, ": ")
if sepIdx != -1 {
actionName = actionName[:sepIdx]
}

switch actionName {
// most frequent event is a health checks
case "health_status":
case "health_status: healthy", "health_status: unhealthy":
sepIdx := strings.Index(actionName, ": ")
healthStatus := e.Action[sepIdx+2:]
if log.IsEnabledFor(logging.DEBUG) {
log.Debugf("handling docker event: action=health_status id=%s %s", e.ID, healthStatus)
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ module github.com/bcicen/ctop
require (
github.com/BurntSushi/toml v0.3.1
github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd
github.com/fsouza/go-dockerclient v1.6.6
github.com/fsouza/go-dockerclient v1.7.0
github.com/gizak/termui v2.3.0+incompatible
github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c
github.com/mattn/go-runewidth v0.0.0-20170201023540-14207d285c6c // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/nsf/termbox-go v0.0.0-20180303152453-e2050e41c884
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473
github.com/opencontainers/runc v1.0.0-rc92
github.com/opencontainers/runc v1.0.0-rc93
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.4.0
)

replace github.com/gizak/termui => github.com/bcicen/termui v0.0.0-20180326052246-4eb80249d3f5
Expand Down
Loading

0 comments on commit 9f8f38f

Please sign in to comment.