Skip to content

Commit

Permalink
[Docker Plugin] add server hostname for each docker measurements (inf…
Browse files Browse the repository at this point in the history
…luxdata#1599)

* add server hostname for each docker measurements

* update CHANGELOG

* move feature to v1.1

* tweak docker_engine_host tag
  • Loading branch information
aaronjheng authored and sparrc committed Sep 6, 2016
1 parent 50ef328 commit 49ea4e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [#1539](https://github.com/influxdata/telegraf/pull/1539): Added capability to send metrics through Http API for OpenTSDB.
- [#1471](https://github.com/influxdata/telegraf/pull/1471): iptables input plugin.
- [#1542](https://github.com/influxdata/telegraf/pull/1542): Add filestack webhook plugin.
- [#1599](https://github.com/influxdata/telegraf/pull/1599): Add server hostname for each docker measurements.

### Bugfixes

Expand Down
15 changes: 9 additions & 6 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type Docker struct {
PerDevice bool `toml:"perdevice"`
Total bool `toml:"total"`

client DockerClient
client DockerClient
engine_host string
}

// DockerClient interface, useful for testing
Expand Down Expand Up @@ -147,6 +148,7 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
if err != nil {
return err
}
d.engine_host = info.Name

fields := map[string]interface{}{
"n_cpus": info.NCPU,
Expand All @@ -159,11 +161,11 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
// Add metrics
acc.AddFields("docker",
fields,
nil,
map[string]string{"engine_host": d.engine_host},
now)
acc.AddFields("docker",
map[string]interface{}{"memory_total": info.MemTotal},
map[string]string{"unit": "bytes"},
map[string]string{"unit": "bytes", "engine_host": d.engine_host},
now)
// Get storage metrics
for _, rawData := range info.DriverStatus {
Expand All @@ -177,7 +179,7 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
// pool blocksize
acc.AddFields("docker",
map[string]interface{}{"pool_blocksize": value},
map[string]string{"unit": "bytes"},
map[string]string{"unit": "bytes", "engine_host": d.engine_host},
now)
} else if strings.HasPrefix(name, "data_space_") {
// data space
Expand All @@ -192,13 +194,13 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error {
if len(dataFields) > 0 {
acc.AddFields("docker_data",
dataFields,
map[string]string{"unit": "bytes"},
map[string]string{"unit": "bytes", "engine_host": d.engine_host},
now)
}
if len(metadataFields) > 0 {
acc.AddFields("docker_metadata",
metadataFields,
map[string]string{"unit": "bytes"},
map[string]string{"unit": "bytes", "engine_host": d.engine_host},
now)
}
return nil
Expand All @@ -225,6 +227,7 @@ func (d *Docker) gatherContainer(
imageVersion = imageParts[1]
}
tags := map[string]string{
"engine_host": d.engine_host,
"container_name": cname,
"container_image": imageName,
"container_version": imageVersion,
Expand Down
7 changes: 5 additions & 2 deletions plugins/inputs/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func TestDockerGatherInfo(t *testing.T) {
"n_images": int(199),
"n_goroutines": int(39),
},
map[string]string{},
map[string]string{"engine_host": "absol"},
)

acc.AssertContainsTaggedFields(t,
Expand All @@ -411,7 +411,8 @@ func TestDockerGatherInfo(t *testing.T) {
"available": int64(36530000000),
},
map[string]string{
"unit": "bytes",
"unit": "bytes",
"engine_host": "absol",
},
)
acc.AssertContainsTaggedFields(t,
Expand All @@ -425,6 +426,7 @@ func TestDockerGatherInfo(t *testing.T) {
"container_image": "quay.io/coreos/etcd",
"cpu": "cpu3",
"container_version": "v2.2.2",
"engine_host": "absol",
},
)
acc.AssertContainsTaggedFields(t,
Expand Down Expand Up @@ -467,6 +469,7 @@ func TestDockerGatherInfo(t *testing.T) {
"container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
},
map[string]string{
"engine_host": "absol",
"container_name": "etcd2",
"container_image": "quay.io/coreos/etcd",
"container_version": "v2.2.2",
Expand Down

0 comments on commit 49ea4e9

Please sign in to comment.