From c7f8800415d21f959efd5716d4a2b1b845ac9ae8 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Wed, 21 Nov 2018 10:48:19 +0100 Subject: [PATCH 1/2] Add flag to disable docker cpu metrics collection per core --- CHANGELOG.asciidoc | 2 ++ metricbeat/docs/modules/docker.asciidoc | 3 +++ metricbeat/metricbeat.reference.yml | 3 +++ metricbeat/module/docker/_meta/config.reference.yml | 3 +++ metricbeat/module/docker/cpu/cpu.go | 11 ++++++++++- metricbeat/module/docker/cpu/helper.go | 13 ++++++++++--- 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index cc853aca9c7..328240363b8 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -66,6 +66,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha1...master[Check the HEAD d *Metricbeat* +- Add setting to disable docker cpu metrics per core. {pull}9194[9194] + *Packetbeat* *Functionbeat* diff --git a/metricbeat/docs/modules/docker.asciidoc b/metricbeat/docs/modules/docker.asciidoc index 4ba7b5ee641..689b1d31de1 100644 --- a/metricbeat/docs/modules/docker.asciidoc +++ b/metricbeat/docs/modules/docker.asciidoc @@ -50,6 +50,9 @@ metricbeat.modules: # If set to true, replace dots in labels with `_`. #labels.dedot: false + # If set to true, collects metrics per core. + #cpu.cores: true + # To connect to Docker over TLS you must specify a client and CA certificate. #ssl: #certificate_authority: "/etc/pki/root/ca.pem" diff --git a/metricbeat/metricbeat.reference.yml b/metricbeat/metricbeat.reference.yml index 4db8f49b71f..24449a776bf 100644 --- a/metricbeat/metricbeat.reference.yml +++ b/metricbeat/metricbeat.reference.yml @@ -178,6 +178,9 @@ metricbeat.modules: # If set to true, replace dots in labels with `_`. #labels.dedot: false + # If set to true, collects metrics per core. + #cpu.cores: true + # To connect to Docker over TLS you must specify a client and CA certificate. #ssl: #certificate_authority: "/etc/pki/root/ca.pem" diff --git a/metricbeat/module/docker/_meta/config.reference.yml b/metricbeat/module/docker/_meta/config.reference.yml index b06bafddfa1..2ac7c913ab3 100644 --- a/metricbeat/module/docker/_meta/config.reference.yml +++ b/metricbeat/module/docker/_meta/config.reference.yml @@ -15,6 +15,9 @@ # If set to true, replace dots in labels with `_`. #labels.dedot: false + # If set to true, collects metrics per core. + #cpu.cores: true + # To connect to Docker over TLS you must specify a client and CA certificate. #ssl: #certificate_authority: "/etc/pki/root/ca.pem" diff --git a/metricbeat/module/docker/cpu/cpu.go b/metricbeat/module/docker/cpu/cpu.go index 4e78f031ac1..954eb37d6d2 100644 --- a/metricbeat/module/docker/cpu/cpu.go +++ b/metricbeat/module/docker/cpu/cpu.go @@ -51,10 +51,19 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { return nil, err } + cpuConfig := struct { + Cores bool `config:"cpu.cores"` + }{ + Cores: true, + } + if err := base.Module().UnpackConfig(&cpuConfig); err != nil { + return nil, err + } + return &MetricSet{ BaseMetricSet: base, dockerClient: client, - cpuService: &CPUService{}, + cpuService: &CPUService{Cores: cpuConfig.Cores}, dedot: config.DeDot, }, nil } diff --git a/metricbeat/module/docker/cpu/helper.go b/metricbeat/module/docker/cpu/helper.go index 03accc2245a..8049e020e12 100644 --- a/metricbeat/module/docker/cpu/helper.go +++ b/metricbeat/module/docker/cpu/helper.go @@ -38,7 +38,9 @@ type CPUStats struct { SystemUsagePercentage float64 } -type CPUService struct{} +type CPUService struct { + Cores bool +} func NewCpuService() *CPUService { return &CPUService{} @@ -57,10 +59,9 @@ func (c *CPUService) getCPUStatsList(rawStats []docker.Stat, dedot bool) []CPUSt func (c *CPUService) getCPUStats(myRawStat *docker.Stat, dedot bool) CPUStats { usage := cpuUsage{Stat: myRawStat} - return CPUStats{ + stats := CPUStats{ Time: common.Time(myRawStat.Stats.Read), Container: docker.NewContainer(myRawStat.Container, dedot), - PerCpuUsage: usage.PerCPU(), TotalUsage: usage.Total(), UsageInKernelmode: myRawStat.Stats.CPUStats.CPUUsage.UsageInKernelmode, UsageInKernelmodePercentage: usage.InKernelMode(), @@ -69,6 +70,12 @@ func (c *CPUService) getCPUStats(myRawStat *docker.Stat, dedot bool) CPUStats { SystemUsage: myRawStat.Stats.CPUStats.SystemUsage, SystemUsagePercentage: usage.System(), } + + if c.Cores { + stats.PerCpuUsage = usage.PerCPU() + } + + return stats } // TODO: These helper should be merged with the cpu helper in system/cpu From 2c83c93f21218f36143751c615d1c3996d565e97 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Wed, 21 Nov 2018 10:54:05 +0100 Subject: [PATCH 2/2] Make hound happy --- metricbeat/module/docker/cpu/helper.go | 1 + 1 file changed, 1 insertion(+) diff --git a/metricbeat/module/docker/cpu/helper.go b/metricbeat/module/docker/cpu/helper.go index 8049e020e12..cfee7ac0d08 100644 --- a/metricbeat/module/docker/cpu/helper.go +++ b/metricbeat/module/docker/cpu/helper.go @@ -38,6 +38,7 @@ type CPUStats struct { SystemUsagePercentage float64 } +// CPUService is a helper to collect docker CPU metrics type CPUService struct { Cores bool }