From 219bf93566515e46b98a91fee309e63c5f818e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 4 May 2016 12:17:23 +0000 Subject: [PATCH] docker: add container_id to blkio metrics all container metrics except blkio have this field closes #1150 --- plugins/inputs/docker/README.md | 1 + plugins/inputs/docker/docker.go | 4 +++- plugins/inputs/docker/docker_test.go | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/docker/README.md b/plugins/inputs/docker/README.md index e59b6f513..52f9a7adb 100644 --- a/plugins/inputs/docker/README.md +++ b/plugins/inputs/docker/README.md @@ -98,6 +98,7 @@ based on the availability of per-cpu stats on your system. - io_serviced_recursive_sync - io_serviced_recursive_total - io_serviced_recursive_write + - container_id - docker_ - n_used_file_descriptors - n_cpus diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index 8a680a8e8..2dc5de1f4 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -328,7 +328,7 @@ func gatherContainerStats( acc.AddFields("docker_container_net", netfields, nettags, now) } - gatherBlockIOMetrics(stat, acc, tags, now) + gatherBlockIOMetrics(stat, acc, tags, now, id) } func calculateMemPercent(stat *types.StatsJSON) float64 { @@ -356,6 +356,7 @@ func gatherBlockIOMetrics( acc telegraf.Accumulator, tags map[string]string, now time.Time, + id string, ) { blkioStats := stat.BlkioStats // Make a map of devices to their block io stats @@ -420,6 +421,7 @@ func gatherBlockIOMetrics( for device, fields := range deviceStatMap { iotags := copyTags(tags) iotags["device"] = device + fields["container_id"] = id acc.AddFields("docker_container_blkio", fields, iotags, now) } } diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index 4ac05f93b..17f0ada6c 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -48,6 +48,7 @@ func TestDockerGatherContainerStats(t *testing.T) { blkiofields := map[string]interface{}{ "io_service_bytes_recursive_read": uint64(100), "io_serviced_recursive_write": uint64(101), + "container_id": "123456789", } acc.AssertContainsTaggedFields(t, "docker_container_blkio", blkiofields, blkiotags)