From 8e29a8bb35d0a1a9b6e57a3a40c4f2d2c9b2becc Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Thu, 19 Apr 2018 13:57:34 +0200 Subject: [PATCH] Metricbeat: Add mapping for docker metrics per cpu (#6843) Fixes #6785 --- CHANGELOG.asciidoc | 1 + libbeat/template/processor.go | 10 +++- libbeat/template/processor_test.go | 32 +++++++++++++ metricbeat/docs/fields.asciidoc | 22 +++++++++ metricbeat/module/docker/cpu/_meta/data.json | 48 ++++++++++++++----- metricbeat/module/docker/cpu/_meta/fields.yml | 16 +++++-- 6 files changed, 110 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 6efce8285f2..04e712dbe81 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -80,6 +80,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Exclude bind mounts in fsstat and filesystem metricsets. {pull}6819[6819] - Don't stop Metricbeat if aerospike server is down. {pull}6874[6874] - disk reads and write count metrics in RabbitMQ queue metricset made optional. {issue}6876[6876] +- Add mapping for docker metrics per cpu. {pull}6843[6843] *Packetbeat* diff --git a/libbeat/template/processor.go b/libbeat/template/processor.go index b98bca748f2..9732bb8b547 100644 --- a/libbeat/template/processor.go +++ b/libbeat/template/processor.go @@ -2,6 +2,7 @@ package template import ( "errors" + "strings" "github.com/elastic/beats/libbeat/common" ) @@ -208,6 +209,9 @@ func (p *Processor) object(f *common.Field) common.MapStr { } switch f.ObjectType { + case "scaled_float": + dynProperties = p.scaledFloat(f) + addDynamicTemplate(f, dynProperties, matchType("*")) case "text": dynProperties["type"] = "text" @@ -242,12 +246,16 @@ func addDynamicTemplate(f *common.Field, properties common.MapStr, matchType str if len(f.Path) > 0 { path = f.Path + "." } + pathMatch := path + f.Name + if !strings.ContainsRune(pathMatch, '*') { + pathMatch += ".*" + } template := common.MapStr{ // Set the path of the field as name path + f.Name: common.MapStr{ "mapping": properties, "match_mapping_type": matchType, - "path_match": path + f.Name + ".*", + "path_match": pathMatch, }, } diff --git a/libbeat/template/processor_test.go b/libbeat/template/processor_test.go index d83c251feaf..af5e04b9e2d 100644 --- a/libbeat/template/processor_test.go +++ b/libbeat/template/processor_test.go @@ -257,6 +257,38 @@ func TestDynamicTemplate(t *testing.T) { }, }, }, + { + field: common.Field{ + Type: "object", ObjectType: "scaled_float", + Name: "core.*.pct", + }, + expected: common.MapStr{ + "core.*.pct": common.MapStr{ + "mapping": common.MapStr{ + "type": "scaled_float", + "scaling_factor": defaultScalingFactor, + }, + "match_mapping_type": "*", + "path_match": "core.*.pct", + }, + }, + }, + { + field: common.Field{ + Type: "object", ObjectType: "scaled_float", + Name: "core.*.pct", ScalingFactor: 100, ObjectTypeMappingType: "float", + }, + expected: common.MapStr{ + "core.*.pct": common.MapStr{ + "mapping": common.MapStr{ + "type": "scaled_float", + "scaling_factor": 100, + }, + "match_mapping_type": "float", + "path_match": "core.*.pct", + }, + }, + }, } for _, test := range tests { diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index f12ca0cf74c..ec847a2c7f5 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -2647,6 +2647,28 @@ format: percentage Total CPU usage. +-- + +*`docker.cpu.core.*.pct`*:: ++ +-- +type: object + +format: percentage + +Percentage of CPU time in this core. + + +-- + +*`docker.cpu.core.*.ticks`*:: ++ +-- +type: object + +Number of CPU ticks in this core. + + -- [float] diff --git a/metricbeat/module/docker/cpu/_meta/data.json b/metricbeat/module/docker/cpu/_meta/data.json index c2afbc08c73..5589d985801 100644 --- a/metricbeat/module/docker/cpu/_meta/data.json +++ b/metricbeat/module/docker/cpu/_meta/data.json @@ -6,33 +6,55 @@ }, "docker": { "container": { - "id": "0b8f7cd09c17df586a8e56f5b2d45dd00735d44fcc2665776d07d33b027b4f09", + "id": "bbdcbc751e7eda7a50e773b4a5d8c2800af664f835ef9c0ad6bbb9c160c50d83", "labels": { - "com_docker_compose_config-hash": "1c0f606c0e592b110060ad4e159cf25d361fb8fa", + "build-date": "20170911", + "com_docker_compose_config-hash": "371e477ae73fd44b19bcbcf0d4feaf4de9adfb69137a8f16d09cff749724ca99", "com_docker_compose_container-number": "1", "com_docker_compose_oneoff": "False", "com_docker_compose_project": "metricbeat", - "com_docker_compose_service": "phpfpm", - "com_docker_compose_version": "1.5.0" + "com_docker_compose_service": "elasticsearch", + "com_docker_compose_version": "1.21.0", + "license": "GPLv2", + "maintainer": "Elastic Docker Team \u003cdocker@elastic.co\u003e", + "name": "CentOS Base Image", + "vendor": "CentOS" }, - "name": "metricbeat_phpfpm_1" + "name": "metricbeat_elasticsearch_1" }, "cpu": { - "core": {}, + "core": { + "0": { + "pct": 0.01012583677581864, + "ticks": 9528454911 + }, + "1": { + "pct": 0.0069975889168765746, + "ticks": 11916812270 + }, + "2": { + "pct": 0.001329603022670025, + "ticks": 10894346015 + }, + "3": { + "pct": 0.0018390015113350126, + "ticks": 10847487614 + } + }, "kernel": { - "pct": 0, - "ticks": 0 + "pct": 0.010075566750629723, + "ticks": 1960000000 }, "system": { - "pct": 0, - "ticks": 0 + "pct": 4, + "ticks": 1092479570000000 }, "total": { - "pct": 0 + "pct": 0.02029203022670025 }, "user": { - "pct": 0, - "ticks": 0 + "pct": 0.010075566750629723, + "ticks": 40960000000 } } }, diff --git a/metricbeat/module/docker/cpu/_meta/fields.yml b/metricbeat/module/docker/cpu/_meta/fields.yml index ca37183bd83..2189fcd986e 100644 --- a/metricbeat/module/docker/cpu/_meta/fields.yml +++ b/metricbeat/module/docker/cpu/_meta/fields.yml @@ -36,8 +36,14 @@ format: percentage description: > Total CPU usage. - # TODO: how to document cpu list? - #- name: core - # type: array - # description: > - # Dictionary with list of cpu and usage inside. + - name: core.*.pct + type: object + object_type: scaled_float + format: percentage + description: > + Percentage of CPU time in this core. + - name: core.*.ticks + type: object + object_type: long + description: > + Number of CPU ticks in this core.