Skip to content

Commit

Permalink
Metricbeat: Add mapping for docker metrics per cpu (#6843)
Browse files Browse the repository at this point in the history
Fixes #6785
  • Loading branch information
jsoriano authored and ruflin committed Apr 19, 2018
1 parent 55fe475 commit 8e29a8b
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
10 changes: 9 additions & 1 deletion libbeat/template/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package template

import (
"errors"
"strings"

"github.com/elastic/beats/libbeat/common"
)
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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,
},
}

Expand Down
32 changes: 32 additions & 0 deletions libbeat/template/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
48 changes: 35 additions & 13 deletions metricbeat/module/docker/cpu/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 \u003c[email protected]\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
}
}
},
Expand Down
16 changes: 11 additions & 5 deletions metricbeat/module/docker/cpu/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 8e29a8b

Please sign in to comment.