Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag to disable docker cpu metrics collection per core #9194

Merged
merged 3 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ 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]
- The `elasticsearch/node` metricset now reports the Elasticsearch cluster UUID. {pull}8771[8771]

*Packetbeat*
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/docs/modules/docker.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/docker/_meta/config.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion metricbeat/module/docker/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 11 additions & 3 deletions metricbeat/module/docker/cpu/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ type CPUStats struct {
SystemUsagePercentage float64
}

type CPUService struct{}
// CPUService is a helper to collect docker CPU metrics
type CPUService struct {
jsoriano marked this conversation as resolved.
Show resolved Hide resolved
Cores bool
}

func NewCpuService() *CPUService {
return &CPUService{}
Expand All @@ -57,10 +60,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(),
Expand All @@ -69,6 +71,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
Expand Down