Skip to content

Commit

Permalink
Add flag to disable docker cpu metrics collection per core (elastic#9194
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jsoriano authored Nov 23, 2018
1 parent f6bbfd5 commit 52df22d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
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 {
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

0 comments on commit 52df22d

Please sign in to comment.