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! - [#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! - [#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 ### Bugfixes

View File

@ -22,6 +22,9 @@ for the stat structure can be found
endpoint = "unix:///var/run/docker.sock" endpoint = "unix:///var/run/docker.sock"
# Only collect metrics for these containers, collect all if empty # Only collect metrics for these containers, collect all if empty
container_names = [] 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: ### Measurements & Fields:

View File

@ -22,9 +22,10 @@ import (
// Docker object // Docker object
type Docker struct { type Docker struct {
Endpoint string Endpoint string
ContainerNames []string ContainerNames []string
Timeout internal.Duration ContainerLabels []string
Timeout internal.Duration
client DockerClient client DockerClient
} }
@ -56,6 +57,9 @@ var sampleConfig = `
endpoint = "unix:///var/run/docker.sock" endpoint = "unix:///var/run/docker.sock"
## Only collect metrics for these containers, collect all if empty ## Only collect metrics for these containers, collect all if empty
container_names = [] 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 for docker list, info, and stats commands
timeout = "5s" timeout = "5s"
` `
@ -232,9 +236,21 @@ func (d *Docker) gatherContainer(
return fmt.Errorf("Error decoding: %s", err.Error()) return fmt.Errorf("Error decoding: %s", err.Error())
} }
// Add labels to tags // Check if there are container labels specified
for k, label := range container.Labels { if len(d.ContainerLabels) == 0 {
tags[k] = label // 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) gatherContainerStats(v, acc, tags, container.ID)