From 676a02271fcffdab89872e52ccaf2624412c368f Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Mon, 8 Jul 2019 16:05:13 +0100 Subject: [PATCH 01/10] Add missing tests for docker storage metrics --- plugins/inputs/docker/docker_test.go | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index e29c6afe9e1aa..a500b6d5f1f40 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -702,6 +702,29 @@ func TestDockerGatherInfo(t *testing.T) { }, ) + acc.AssertContainsTaggedFields(t, + "docker", + map[string]interface{}{ + "memory_total": int64(3840757760), + }, + map[string]string{ + "engine_host": "absol", + "server_version": "17.09.0-ce", + }, + ) + + acc.AssertContainsTaggedFields(t, + "docker", + map[string]interface{}{ + "pool_blocksize": int64(65540), + }, + map[string]string{ + "engine_host": "absol", + "server_version": "17.09.0-ce", + "unit": "bytes", + }, + ) + acc.AssertContainsTaggedFields(t, "docker_data", map[string]interface{}{ @@ -710,11 +733,26 @@ func TestDockerGatherInfo(t *testing.T) { "available": int64(36530000000), }, map[string]string{ + "engine_host": "absol", + "server_version": "17.09.0-ce", "unit": "bytes", + }, + ) + + acc.AssertContainsTaggedFields(t, + "docker_metadata", + map[string]interface{}{ + "used": int64(20970000), + "total": int64(2146999999), + "available": int64(2126999999), + }, + map[string]string{ "engine_host": "absol", "server_version": "17.09.0-ce", + "unit": "bytes", }, ) + acc.AssertContainsTaggedFields(t, "docker_container_cpu", map[string]interface{}{ From 16e478efe22d3de7057e7b76193324071a08564c Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Mon, 8 Jul 2019 16:11:20 +0100 Subject: [PATCH 02/10] Add failing test case for docker input plugin thinpool minimum free space measurement --- plugins/inputs/docker/docker_test.go | 12 ++++++++++++ plugins/inputs/docker/docker_testdata.go | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index a500b6d5f1f40..1dee2f67ec84f 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -753,6 +753,18 @@ func TestDockerGatherInfo(t *testing.T) { }, ) + acc.AssertContainsTaggedFields(t, + "docker_thinpool", + map[string]interface{}{ + "minimum_free_space": int64(10740000000), + }, + map[string]string{ + "engine_host": "absol", + "server_version": "17.09.0-ce", + "unit": "bytes", + }, + ) + acc.AssertContainsTaggedFields(t, "docker_container_cpu", map[string]interface{}{ diff --git a/plugins/inputs/docker/docker_testdata.go b/plugins/inputs/docker/docker_testdata.go index ba5c2ffa17bdd..196e912d3a1ba 100644 --- a/plugins/inputs/docker/docker_testdata.go +++ b/plugins/inputs/docker/docker_testdata.go @@ -47,7 +47,7 @@ var info = types.Info{ HTTPSProxy: "", Labels: []string{}, MemoryLimit: false, - DriverStatus: [][2]string{{"Pool Name", "docker-8:1-1182287-pool"}, {"Pool Blocksize", "65.54 kB"}, {"Backing Filesystem", "extfs"}, {"Data file", "/dev/loop0"}, {"Metadata file", "/dev/loop1"}, {"Data Space Used", "17.3 GB"}, {"Data Space Total", "107.4 GB"}, {"Data Space Available", "36.53 GB"}, {"Metadata Space Used", "20.97 MB"}, {"Metadata Space Total", "2.147 GB"}, {"Metadata Space Available", "2.127 GB"}, {"Udev Sync Supported", "true"}, {"Deferred Removal Enabled", "false"}, {"Data loop file", "/var/lib/docker/devicemapper/devicemapper/data"}, {"Metadata loop file", "/var/lib/docker/devicemapper/devicemapper/metadata"}, {"Library Version", "1.02.115 (2016-01-25)"}}, + DriverStatus: [][2]string{{"Pool Name", "docker-8:1-1182287-pool"}, {"Pool Blocksize", "65.54 kB"}, {"Backing Filesystem", "extfs"}, {"Data file", "/dev/loop0"}, {"Metadata file", "/dev/loop1"}, {"Data Space Used", "17.3 GB"}, {"Data Space Total", "107.4 GB"}, {"Data Space Available", "36.53 GB"}, {"Metadata Space Used", "20.97 MB"}, {"Metadata Space Total", "2.147 GB"}, {"Metadata Space Available", "2.127 GB"}, {"Udev Sync Supported", "true"}, {"Deferred Removal Enabled", "false"}, {"Data loop file", "/var/lib/docker/devicemapper/devicemapper/data"}, {"Metadata loop file", "/var/lib/docker/devicemapper/devicemapper/metadata"}, {"Library Version", "1.02.115 (2016-01-25)"}, {"Thin Pool Minimum Free Space", "10.74GB"}}, NFd: 19, HTTPProxy: "", Driver: "devicemapper", From 20cf74c6f18a59dc8a6028865247f211b96abd8e Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Mon, 8 Jul 2019 16:14:03 +0100 Subject: [PATCH 03/10] Measure docker devicemapper thin pool minimum free space in docker input plugin --- plugins/inputs/docker/docker.go | 5 +++++ plugins/inputs/docker/docker_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index 355b8cd8a5789..8d261e6f8e396 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -343,6 +343,11 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error { map[string]interface{}{"pool_blocksize": value}, tags, now) + } else if name == "thin_pool_minimum_free_space" { + acc.AddFields("docker_thin_pool", + map[string]interface{}{"minimum_free_space": value}, + tags, + now) } else if strings.HasPrefix(name, "data_space_") { // data space fieldName := strings.TrimPrefix(name, "data_space_") diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index 1dee2f67ec84f..5fec591578bb3 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -754,7 +754,7 @@ func TestDockerGatherInfo(t *testing.T) { ) acc.AssertContainsTaggedFields(t, - "docker_thinpool", + "docker_thin_pool", map[string]interface{}{ "minimum_free_space": int64(10740000000), }, From 207c09e0c59a7e079ca67c2f1ede01ba8c6d09c9 Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Tue, 9 Jul 2019 09:36:41 +0100 Subject: [PATCH 04/10] Add failing check to docker input plugin tests to replace docker_thin_pool with docker_devicemapper --- plugins/inputs/docker/docker_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index 5fec591578bb3..f4fbc10bf9113 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -754,14 +754,21 @@ func TestDockerGatherInfo(t *testing.T) { ) acc.AssertContainsTaggedFields(t, - "docker_thin_pool", + "docker_devicemapper", map[string]interface{}{ - "minimum_free_space": int64(10740000000), + "pool_blocksize_bytes": int64(65540), + "data_space_used_bytes": int64(17300000000), + "data_space_total_bytes": int64(107400000000), + "data_space_available_bytes": int64(36530000000), + "metadata_space_used_bytes": int64(20970000), + "metadata_space_total_bytes": int64(2146999999), + "metadata_space_available_bytes": int64(2126999999), + "thin_pool_minimum_free_space_bytes": int64(10740000000), }, map[string]string{ "engine_host": "absol", "server_version": "17.09.0-ce", - "unit": "bytes", + "pool_name": "docker-8:1-1182287-pool", }, ) From b38d6aded794131aea3d2b2e4446d9e0fe252a98 Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Tue, 9 Jul 2019 09:52:43 +0100 Subject: [PATCH 05/10] Add measurement docker_devicemapper to docker input plugin --- plugins/inputs/docker/docker.go | 51 +++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index 8d261e6f8e396..e85f08f1590da 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -322,32 +322,55 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error { "n_goroutines": info.NGoroutines, "n_listener_events": info.NEventsListener, } + // Add metrics acc.AddFields("docker", fields, tags, now) acc.AddFields("docker", map[string]interface{}{"memory_total": info.MemTotal}, tags, now) + // Get storage metrics tags["unit"] = "bytes" + + var ( + // "docker_devicemapper" measurement fields + poolName string + deviceMapperFields = map[string]interface{}{} + ) + for _, rawData := range info.DriverStatus { + name := strings.ToLower(strings.Replace(rawData[0], " ", "_", -1)) + if name == "pool_name" { + poolName = rawData[1] + continue + } + // Try to convert string to int (bytes) value, err := parseSize(rawData[1]) if err != nil { continue } - name := strings.ToLower(strings.Replace(rawData[0], " ", "_", -1)) + + switch name { + case "pool_blocksize", + "data_space_used", + "data_space_total", + "data_space_available", + "metadata_space_used", + "metadata_space_total", + "metadata_space_available", + "thin_pool_minimum_free_space": + deviceMapperFields[fmt.Sprintf("%s_bytes", name)] = value + } + + // Legacy devicemapper measurements if name == "pool_blocksize" { // pool blocksize acc.AddFields("docker", map[string]interface{}{"pool_blocksize": value}, tags, now) - } else if name == "thin_pool_minimum_free_space" { - acc.AddFields("docker_thin_pool", - map[string]interface{}{"minimum_free_space": value}, - tags, - now) } else if strings.HasPrefix(name, "data_space_") { // data space fieldName := strings.TrimPrefix(name, "data_space_") @@ -358,12 +381,28 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error { metadataFields[fieldName] = value } } + if len(dataFields) > 0 { acc.AddFields("docker_data", dataFields, tags, now) } + if len(metadataFields) > 0 { acc.AddFields("docker_metadata", metadataFields, tags, now) } + + if len(deviceMapperFields) > 0 { + tags := map[string]string{ + "engine_host": d.engineHost, + "server_version": d.serverVersion, + } + + if poolName != "" { + tags["pool_name"] = poolName + } + + acc.AddFields("docker_devicemapper", deviceMapperFields, tags, now) + } + return nil } From e4461d09ab80e7068787596aec04fbc358bc9b75 Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Tue, 9 Jul 2019 10:01:40 +0100 Subject: [PATCH 06/10] Add docker_devicemapper measurement to docker input plugin README --- plugins/inputs/docker/README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/docker/README.md b/plugins/inputs/docker/README.md index e8c8d63664b8f..21adaa885acf0 100644 --- a/plugins/inputs/docker/README.md +++ b/plugins/inputs/docker/README.md @@ -117,12 +117,12 @@ may prefer to exclude them: - n_goroutines - n_listener_events - memory_total - - pool_blocksize (requires devicemapper storage driver) + - pool_blocksize (requires devicemapper storage driver) (deprecated see: `docker_devicemapper`) The `docker_data` and `docker_metadata` measurements are available only for some storage drivers such as devicemapper. -- docker_data +- docker_data (deprecated see: `docker_devicemapper`) - tags: - unit - engine_host @@ -132,7 +132,7 @@ some storage drivers such as devicemapper. - total - used -- docker_metadata +- docker_metadata (deprecated see: `docker_devicemapper`) - tags: - unit - engine_host @@ -142,6 +142,23 @@ some storage drivers such as devicemapper. - total - used +The above measurements for the devicemapper storage driver can now be found in the new `docker_devicemapper` measurement + +- docker_devicemapper + - tags: + - engine_host + - server_version + - pool_name + - fields: + - pool_blocksize_bytes + - data_space_used_bytes + - data_space_total_bytes + - data_space_available_bytes + - metadata_space_used_bytes + - metadata_space_total_bytes + - metadata_space_available_bytes + - thin_pool_minimum_free_space_bytes + - docker_container_mem - tags: - engine_host From f2beb179ccccf46e2476b5175fbdc5562435c728 Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Wed, 10 Jul 2019 10:39:36 +0100 Subject: [PATCH 07/10] Add failing case for devicemapper base device size (docker input plugin) --- plugins/inputs/docker/docker.go | 2 +- plugins/inputs/docker/docker_test.go | 1 + plugins/inputs/docker/docker_testdata.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index e85f08f1590da..d622551a29fda 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -361,7 +361,7 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error { "metadata_space_total", "metadata_space_available", "thin_pool_minimum_free_space": - deviceMapperFields[fmt.Sprintf("%s_bytes", name)] = value + deviceMapperFields[name+"_bytes"] = value } // Legacy devicemapper measurements diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index f4fbc10bf9113..b340ea8f30457 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -756,6 +756,7 @@ func TestDockerGatherInfo(t *testing.T) { acc.AssertContainsTaggedFields(t, "docker_devicemapper", map[string]interface{}{ + "base_device_size_bytes": int64(107400000000), "pool_blocksize_bytes": int64(65540), "data_space_used_bytes": int64(17300000000), "data_space_total_bytes": int64(107400000000), diff --git a/plugins/inputs/docker/docker_testdata.go b/plugins/inputs/docker/docker_testdata.go index 196e912d3a1ba..d50b80b9a1d1d 100644 --- a/plugins/inputs/docker/docker_testdata.go +++ b/plugins/inputs/docker/docker_testdata.go @@ -47,7 +47,7 @@ var info = types.Info{ HTTPSProxy: "", Labels: []string{}, MemoryLimit: false, - DriverStatus: [][2]string{{"Pool Name", "docker-8:1-1182287-pool"}, {"Pool Blocksize", "65.54 kB"}, {"Backing Filesystem", "extfs"}, {"Data file", "/dev/loop0"}, {"Metadata file", "/dev/loop1"}, {"Data Space Used", "17.3 GB"}, {"Data Space Total", "107.4 GB"}, {"Data Space Available", "36.53 GB"}, {"Metadata Space Used", "20.97 MB"}, {"Metadata Space Total", "2.147 GB"}, {"Metadata Space Available", "2.127 GB"}, {"Udev Sync Supported", "true"}, {"Deferred Removal Enabled", "false"}, {"Data loop file", "/var/lib/docker/devicemapper/devicemapper/data"}, {"Metadata loop file", "/var/lib/docker/devicemapper/devicemapper/metadata"}, {"Library Version", "1.02.115 (2016-01-25)"}, {"Thin Pool Minimum Free Space", "10.74GB"}}, + DriverStatus: [][2]string{{"Pool Name", "docker-8:1-1182287-pool"}, {"Base Device Size", "10.74 GB"}, {"Pool Blocksize", "65.54 kB"}, {"Backing Filesystem", "extfs"}, {"Data file", "/dev/loop0"}, {"Metadata file", "/dev/loop1"}, {"Data Space Used", "17.3 GB"}, {"Data Space Total", "107.4 GB"}, {"Data Space Available", "36.53 GB"}, {"Metadata Space Used", "20.97 MB"}, {"Metadata Space Total", "2.147 GB"}, {"Metadata Space Available", "2.127 GB"}, {"Udev Sync Supported", "true"}, {"Deferred Removal Enabled", "false"}, {"Data loop file", "/var/lib/docker/devicemapper/devicemapper/data"}, {"Metadata loop file", "/var/lib/docker/devicemapper/devicemapper/metadata"}, {"Library Version", "1.02.115 (2016-01-25)"}, {"Thin Pool Minimum Free Space", "10.74GB"}}, NFd: 19, HTTPProxy: "", Driver: "devicemapper", From 117e7a590318085b1c2d006b4931a053fedc7f79 Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Wed, 10 Jul 2019 10:51:10 +0100 Subject: [PATCH 08/10] Measure base device size of devicemapper storage driver (docker input plugin) --- plugins/inputs/docker/docker.go | 1 + plugins/inputs/docker/docker_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/docker/docker.go b/plugins/inputs/docker/docker.go index d622551a29fda..00e6f58e79906 100644 --- a/plugins/inputs/docker/docker.go +++ b/plugins/inputs/docker/docker.go @@ -354,6 +354,7 @@ func (d *Docker) gatherInfo(acc telegraf.Accumulator) error { switch name { case "pool_blocksize", + "base_device_size", "data_space_used", "data_space_total", "data_space_available", diff --git a/plugins/inputs/docker/docker_test.go b/plugins/inputs/docker/docker_test.go index b340ea8f30457..77228b00cad47 100644 --- a/plugins/inputs/docker/docker_test.go +++ b/plugins/inputs/docker/docker_test.go @@ -756,7 +756,7 @@ func TestDockerGatherInfo(t *testing.T) { acc.AssertContainsTaggedFields(t, "docker_devicemapper", map[string]interface{}{ - "base_device_size_bytes": int64(107400000000), + "base_device_size_bytes": int64(10740000000), "pool_blocksize_bytes": int64(65540), "data_space_used_bytes": int64(17300000000), "data_space_total_bytes": int64(107400000000), From e944107bf1a5c5993971a9b2151cccb4f008ca92 Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Wed, 10 Jul 2019 11:00:30 +0100 Subject: [PATCH 09/10] Update docker input plugin devicemapper README list formatting --- plugins/inputs/docker/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/docker/README.md b/plugins/inputs/docker/README.md index 21adaa885acf0..504a1f5749f56 100644 --- a/plugins/inputs/docker/README.md +++ b/plugins/inputs/docker/README.md @@ -106,7 +106,7 @@ may prefer to exclude them: - unit - engine_host - server_version - - fields: + + fields: - n_used_file_descriptors - n_cpus - n_containers @@ -122,12 +122,12 @@ may prefer to exclude them: The `docker_data` and `docker_metadata` measurements are available only for some storage drivers such as devicemapper. -- docker_data (deprecated see: `docker_devicemapper`) ++ docker_data (deprecated see: `docker_devicemapper`) - tags: - unit - engine_host - server_version - - fields: + + fields: - available - total - used @@ -137,7 +137,7 @@ some storage drivers such as devicemapper. - unit - engine_host - server_version - - fields: + + fields: - available - total - used @@ -149,7 +149,7 @@ The above measurements for the devicemapper storage driver can now be found in t - engine_host - server_version - pool_name - - fields: + + fields: - pool_blocksize_bytes - data_space_used_bytes - data_space_total_bytes From eca9d20fd1f8968568018d19c66e6559eb5bed86 Mon Sep 17 00:00:00 2001 From: George MacRorie Date: Wed, 10 Jul 2019 11:02:52 +0100 Subject: [PATCH 10/10] Further docker input plugin devicemapper README list formatting --- plugins/inputs/docker/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/inputs/docker/README.md b/plugins/inputs/docker/README.md index 504a1f5749f56..c909b66835260 100644 --- a/plugins/inputs/docker/README.md +++ b/plugins/inputs/docker/README.md @@ -159,7 +159,7 @@ The above measurements for the devicemapper storage driver can now be found in t - metadata_space_available_bytes - thin_pool_minimum_free_space_bytes -- docker_container_mem ++ docker_container_mem - tags: - engine_host - server_version @@ -167,7 +167,7 @@ The above measurements for the devicemapper storage driver can now be found in t - container_name - container_status - container_version - - fields: + + fields: - total_pgmafault - cache - mapped_file @@ -212,7 +212,7 @@ The above measurements for the devicemapper storage driver can now be found in t - container_status - container_version - cpu - - fields: + + fields: - throttling_periods - throttling_throttled_periods - throttling_throttled_time @@ -223,7 +223,7 @@ The above measurements for the devicemapper storage driver can now be found in t - usage_percent - container_id -- docker_container_net ++ docker_container_net - tags: - engine_host - server_version @@ -232,7 +232,7 @@ The above measurements for the devicemapper storage driver can now be found in t - container_status - container_version - network - - fields: + + fields: - rx_dropped - rx_bytes - rx_errors