From 5deb22a539ff458833a84a5122dcc382b5f2c291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 9 May 2016 08:22:53 +0000 Subject: [PATCH] docker: add container_id also to per cpu stats currently this field exists only for total cpu usage closes #1168 --- plugins/inputs/docker/docker.go | 6 +++++- plugins/inputs/docker/docker_test.go | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index 2dc5de1f4..79d506e9a 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -307,7 +307,11 @@ func gatherContainerStats( for i, percpu := range stat.CPUStats.CPUUsage.PercpuUsage { percputags := copyTags(tags) percputags["cpu"] = fmt.Sprintf("cpu%d", i) - acc.AddFields("docker_container_cpu", map[string]interface{}{"usage_total": percpu}, percputags, now) + fields := map[string]interface{}{ + "usage_total": percpu, + "container_id": id, + } + acc.AddFields("docker_container_cpu", fields, percputags, now) } for network, netstats := range stat.Networks { diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index 17f0ada6c..1574009b8 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -111,13 +111,15 @@ func TestDockerGatherContainerStats(t *testing.T) { cputags["cpu"] = "cpu0" cpu0fields := map[string]interface{}{ - "usage_total": uint64(1), + "usage_total": uint64(1), + "container_id": "123456789", } acc.AssertContainsTaggedFields(t, "docker_container_cpu", cpu0fields, cputags) cputags["cpu"] = "cpu1" cpu1fields := map[string]interface{}{ - "usage_total": uint64(1002), + "usage_total": uint64(1002), + "container_id": "123456789", } acc.AssertContainsTaggedFields(t, "docker_container_cpu", cpu1fields, cputags) } @@ -372,7 +374,8 @@ func TestDockerGatherInfo(t *testing.T) { acc.AssertContainsTaggedFields(t, "docker_container_cpu", map[string]interface{}{ - "usage_total": uint64(1231652), + "usage_total": uint64(1231652), + "container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173", }, map[string]string{ "container_name": "etcd2",