Skip to content

Commit

Permalink
optionally disable metrics reporting for non-running containers
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Cerutti committed May 12, 2017
1 parent a47aa0d commit c5c6d47
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions plugins/inputs/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ for the stat structure can be found
## Note that an empty array for both will include all labels as tags
docker_label_include = []
docker_label_exclude = []
## disable metrics collection for non-running containers
only_running = true
```

Expand Down
17 changes: 13 additions & 4 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type Docker struct {

testing bool
labelFiltersCreated bool

onlyRunning bool `toml:"only_running"`
}

// infoWrapper wraps client.Client.List for testing.
Expand Down Expand Up @@ -112,6 +114,10 @@ var sampleConfig = `
## Note that an empty array for both will include all labels as tags
docker_label_include = []
docker_label_exclude = []
## Only monitor running containers
only_running = true
`

// Description returns input description
Expand Down Expand Up @@ -176,10 +182,13 @@ func (d *Docker) Gather(acc telegraf.Accumulator) error {
for _, container := range containers {
go func(c types.Container) {
defer wg.Done()
err := d.gatherContainer(c, acc)
if err != nil {
acc.AddError(fmt.Errorf("E! Error gathering container %s stats: %s\n",
c.Names, err.Error()))

if (d.onlyRunning && c.State == "running") || (!d.onlyRunning) {
err := d.gatherContainer(c, acc)
if err != nil {
acc.AddError(fmt.Errorf("E! Error gathering container %s stats: %s\n",
c.Names, err.Error()))
}
}
}(container)
}
Expand Down

0 comments on commit c5c6d47

Please sign in to comment.