Added container_labels parameter

This commit is contained in:
Tim Scheuermann 2016-05-25 14:31:44 +02:00
parent 58f2ba1247
commit 63bd8b0206
3 changed files with 26 additions and 6 deletions

View File

@ -21,6 +21,7 @@ time before a new metric is included by the plugin.
- [#1247](https://github.com/influxdata/telegraf/pull/1247): rollbar input plugin. Thanks @francois2metz and @cduez!
- [#1208](https://github.com/influxdata/telegraf/pull/1208): Standardized AWS credentials evaluation & wildcard CloudWatch dimensions. Thanks @johnrengelman!
- [#1263](https://github.com/influxdata/telegraf/issues/1263): Added container_labels to docker plugin
### Bugfixes

View File

@ -22,6 +22,9 @@ for the stat structure can be found
endpoint = "unix:///var/run/docker.sock"
# Only collect metrics for these containers, collect all if empty
container_names = []
## Only collect these container labels from docker daemon, collect all if empty but note that
## this will break prometheus output if containers have inconsistent label sets.
container_labels = []
```
### Measurements & Fields:

View File

@ -22,9 +22,10 @@ import (
// Docker object
type Docker struct {
Endpoint string
ContainerNames []string
Timeout internal.Duration
Endpoint string
ContainerNames []string
ContainerLabels []string
Timeout internal.Duration
client DockerClient
}
@ -56,6 +57,9 @@ var sampleConfig = `
endpoint = "unix:///var/run/docker.sock"
## Only collect metrics for these containers, collect all if empty
container_names = []
## Only collect these container labels from docker daemon, collect all if empty but note that
## this will break prometheus output if containers have inconsistent label sets.
container_labels = []
## Timeout for docker list, info, and stats commands
timeout = "5s"
`
@ -232,9 +236,21 @@ func (d *Docker) gatherContainer(
return fmt.Errorf("Error decoding: %s", err.Error())
}
// Add labels to tags
for k, label := range container.Labels {
tags[k] = label
// Check if there are container labels specified
if len(d.ContainerLabels) == 0 {
// Add all labels to tags
for k, label := range container.Labels {
tags[k] = label
}
} else {
// Omit labels not in d.ContainerLabels and add placeholders for missing labels
for _, l := range d.ContainerLabels {
if label, ok := container.Labels[l]; ok {
tags[l] = label
} else {
tags[l] = "-"
}
}
}
gatherContainerStats(v, acc, tags, container.ID)