Skip to content

Commit

Permalink
Cherry-pick #15070 to 7.5: fallback to different CPU calculation if w…
Browse files Browse the repository at this point in the history
…e have no online_cpu count (#15082)

* [metricbeat] Fallback to different CPU calculation if we have no online_cpu count (#15070)
  • Loading branch information
fearful-symmetry committed Dec 12, 2019
1 parent 6420fbe commit 60dd883
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Closing handler after verifying the registry key in diskio metricset. {issue}14683[14683] {pull}14759[14759]
- Fix docker network stats when multiple interfaces are configured. {issue}14586[14586] {pull}14825[14825]
- Fix ListMetrics pagination in aws module. {issue}14926[14926] {pull}14942[14942]
- Fix CPU count in docker/cpu in cases where no `online_cpus` are reported {pull}15070[15070]

*Packetbeat*

Expand Down
15 changes: 14 additions & 1 deletion metricbeat/module/docker/cpu/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,20 @@ type cpuUsage struct {
// be updated/initialized with the corresponding value retrieved from Docker API.
func (u *cpuUsage) CPUs() uint32 {
if u.cpus == 0 {
u.cpus = u.Stats.CPUStats.OnlineCPUs
if u.Stats.CPUStats.OnlineCPUs != 0 {
u.cpus = u.Stats.CPUStats.OnlineCPUs
} else {
//Certain versions of docker don't have `online_cpus`
//In addition to this, certain kernel versions will report spurious zeros from the cgroups usage_percpu
var realCPUCount uint32
for _, rCPUUsage := range u.Stats.CPUStats.CPUUsage.PercpuUsage {
if rCPUUsage != 0 {
realCPUCount++
}
}
u.cpus = realCPUCount
}

}
return u.cpus
}
Expand Down

0 comments on commit 60dd883

Please sign in to comment.