From 0e9088ffb84bc506bee259624f7d8dc12512a21f Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Tue, 12 Apr 2016 14:59:19 -0600 Subject: [PATCH] Remove cont_id tag from docker plugin also renaming cont_name and cont_image to container_name and container_image. closes #1014 --- plugins/inputs/docker/docker.go | 35 +++++++++-------- plugins/inputs/docker/docker_test.go | 59 ++++++++++++++-------------- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index 094bad8ca71ed..3e9db8e3a210a 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -200,9 +200,8 @@ func (d *Docker) gatherContainer( } tags := map[string]string{ - "cont_id": container.ID, - "cont_name": cname, - "cont_image": container.Image, + "container_name": cname, + "container_image": container.Image, } if len(d.ContainerNames) > 0 { if !sliceContains(cname, d.ContainerNames) { @@ -225,7 +224,7 @@ func (d *Docker) gatherContainer( tags[k] = v } - gatherContainerStats(v, acc, tags) + gatherContainerStats(v, acc, tags, container.ID) return nil } @@ -234,6 +233,7 @@ func gatherContainerStats( stat *types.StatsJSON, acc telegraf.Accumulator, tags map[string]string, + id string, ) { now := stat.Read @@ -272,8 +272,9 @@ func gatherContainerStats( "inactive_file": stat.MemoryStats.Stats["inactive_file"], "total_pgpgin": stat.MemoryStats.Stats["total_pgpgin"], "usage_percent": calculateMemPercent(stat), + "container_id": id, } - acc.AddFields("docker_mem", memfields, tags, now) + acc.AddFields("docker_container_mem", memfields, tags, now) cpufields := map[string]interface{}{ "usage_total": stat.CPUStats.CPUUsage.TotalUsage, @@ -284,32 +285,34 @@ func gatherContainerStats( "throttling_throttled_periods": stat.CPUStats.ThrottlingData.ThrottledPeriods, "throttling_throttled_time": stat.CPUStats.ThrottlingData.ThrottledTime, "usage_percent": calculateCPUPercent(stat), + "container_id": id, } cputags := copyTags(tags) cputags["cpu"] = "cpu-total" - acc.AddFields("docker_cpu", cpufields, cputags, now) + acc.AddFields("docker_container_cpu", cpufields, cputags, now) for i, percpu := range stat.CPUStats.CPUUsage.PercpuUsage { percputags := copyTags(tags) percputags["cpu"] = fmt.Sprintf("cpu%d", i) - acc.AddFields("docker_cpu", map[string]interface{}{"usage_total": percpu}, percputags, now) + acc.AddFields("docker_container_cpu", map[string]interface{}{"usage_total": percpu}, percputags, now) } for network, netstats := range stat.Networks { netfields := map[string]interface{}{ - "rx_dropped": netstats.RxDropped, - "rx_bytes": netstats.RxBytes, - "rx_errors": netstats.RxErrors, - "tx_packets": netstats.TxPackets, - "tx_dropped": netstats.TxDropped, - "rx_packets": netstats.RxPackets, - "tx_errors": netstats.TxErrors, - "tx_bytes": netstats.TxBytes, + "rx_dropped": netstats.RxDropped, + "rx_bytes": netstats.RxBytes, + "rx_errors": netstats.RxErrors, + "tx_packets": netstats.TxPackets, + "tx_dropped": netstats.TxDropped, + "rx_packets": netstats.RxPackets, + "tx_errors": netstats.TxErrors, + "tx_bytes": netstats.TxBytes, + "container_id": id, } // Create a new network tag dictionary for the "network" tag nettags := copyTags(tags) nettags["network"] = network - acc.AddFields("docker_net", netfields, nettags, now) + acc.AddFields("docker_container_net", netfields, nettags, now) } gatherBlockIOMetrics(stat, acc, tags, now) diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index c9fe6cea17927..05069ba5327b0 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -21,26 +21,26 @@ func TestDockerGatherContainerStats(t *testing.T) { stats := testStats() tags := map[string]string{ - "cont_id": "foobarbaz", - "cont_name": "redis", - "cont_image": "redis/image", + "container_name": "redis", + "container_image": "redis/image", } - gatherContainerStats(stats, &acc, tags) + gatherContainerStats(stats, &acc, tags, "123456789") - // test docker_net measurement + // test docker_container_net measurement netfields := map[string]interface{}{ - "rx_dropped": uint64(1), - "rx_bytes": uint64(2), - "rx_errors": uint64(3), - "tx_packets": uint64(4), - "tx_dropped": uint64(1), - "rx_packets": uint64(2), - "tx_errors": uint64(3), - "tx_bytes": uint64(4), + "rx_dropped": uint64(1), + "rx_bytes": uint64(2), + "rx_errors": uint64(3), + "tx_packets": uint64(4), + "tx_dropped": uint64(1), + "rx_packets": uint64(2), + "tx_errors": uint64(3), + "tx_bytes": uint64(4), + "container_id": "123456789", } nettags := copyTags(tags) nettags["network"] = "eth0" - acc.AssertContainsTaggedFields(t, "docker_net", netfields, nettags) + acc.AssertContainsTaggedFields(t, "docker_container_net", netfields, nettags) // test docker_blkio measurement blkiotags := copyTags(tags) @@ -51,7 +51,7 @@ func TestDockerGatherContainerStats(t *testing.T) { } acc.AssertContainsTaggedFields(t, "docker_blkio", blkiofields, blkiotags) - // test docker_mem measurement + // test docker_container_mem measurement memfields := map[string]interface{}{ "max_usage": uint64(1001), "usage": uint64(1111), @@ -87,11 +87,12 @@ func TestDockerGatherContainerStats(t *testing.T) { "inactive_file": uint64(3), "total_pgpgin": uint64(4), "usage_percent": float64(55.55), + "container_id": "123456789", } - acc.AssertContainsTaggedFields(t, "docker_mem", memfields, tags) + acc.AssertContainsTaggedFields(t, "docker_container_mem", memfields, tags) - // test docker_cpu measurement + // test docker_container_cpu measurement cputags := copyTags(tags) cputags["cpu"] = "cpu-total" cpufields := map[string]interface{}{ @@ -103,20 +104,21 @@ func TestDockerGatherContainerStats(t *testing.T) { "throttling_throttled_periods": uint64(0), "throttling_throttled_time": uint64(0), "usage_percent": float64(400.0), + "container_id": "123456789", } - acc.AssertContainsTaggedFields(t, "docker_cpu", cpufields, cputags) + acc.AssertContainsTaggedFields(t, "docker_container_cpu", cpufields, cputags) cputags["cpu"] = "cpu0" cpu0fields := map[string]interface{}{ "usage_total": uint64(1), } - acc.AssertContainsTaggedFields(t, "docker_cpu", cpu0fields, cputags) + acc.AssertContainsTaggedFields(t, "docker_container_cpu", cpu0fields, cputags) cputags["cpu"] = "cpu1" cpu1fields := map[string]interface{}{ "usage_total": uint64(1002), } - acc.AssertContainsTaggedFields(t, "docker_cpu", cpu1fields, cputags) + acc.AssertContainsTaggedFields(t, "docker_container_cpu", cpu1fields, cputags) } func testStats() *types.StatsJSON { @@ -367,19 +369,18 @@ func TestDockerGatherInfo(t *testing.T) { }, ) acc.AssertContainsTaggedFields(t, - "docker_cpu", + "docker_container_cpu", map[string]interface{}{ "usage_total": uint64(1231652), }, map[string]string{ - "cont_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173", - "cont_name": "etcd2", - "cont_image": "quay.io/coreos/etcd:v2.2.2", - "cpu": "cpu3", + "container_name": "etcd2", + "container_image": "quay.io/coreos/etcd:v2.2.2", + "cpu": "cpu3", }, ) acc.AssertContainsTaggedFields(t, - "docker_mem", + "docker_container_mem", map[string]interface{}{ "total_pgpgout": uint64(0), "usage_percent": float64(0), @@ -415,11 +416,11 @@ func TestDockerGatherInfo(t *testing.T) { "pgfault": uint64(0), "usage": uint64(0), "limit": uint64(18935443456), + "container_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173", }, map[string]string{ - "cont_id": "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173", - "cont_name": "etcd2", - "cont_image": "quay.io/coreos/etcd:v2.2.2", + "container_name": "etcd2", + "container_image": "quay.io/coreos/etcd:v2.2.2", }, )