Skip to content

Commit

Permalink
Calculate memory usage percentage in Windows kubernetes pods (#25428) (
Browse files Browse the repository at this point in the history
…#25470)

In Windows native containers usage memory is reported
using the workingSet. Use this value to calculate memory
usage percentage.

(cherry picked from commit 381e062)

Co-authored-by: Brian Harwell <brianharwell@gmail.com>
Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
  • Loading branch information
3 people committed May 5, 2021
1 parent 052b8dc commit 741ca40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix GCP not able to request Cloudfunctions metrics if a region filter was set {pull}24218[24218]
- Fix type of `uwsgi.status.worker.rss` type. {pull}24468[24468]
- Accept text/plain type by default for prometheus client scraping. {pull}24622[24622]
- Use working set bytes to calculate the pod memory limit pct when memory usage is not reported (ie. Windows pods). {pull}25428[25428]
- Fix copy-paste error in libbeat docs. {pull}25448[25448]

*Packetbeat*
Expand Down
22 changes: 16 additions & 6 deletions metricbeat/module/kubernetes/pod/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,26 @@ func eventMapping(content []byte, perfMetrics *util.PerfMetricsCache) ([]common.
podEvent.Put("cpu.usage.node.pct", float64(usageNanoCores)/1e9/nodeCores)
}

if nodeMem > 0 {
podEvent.Put("memory.usage.node.pct", float64(usageMem)/nodeMem)
}

if coresLimit > 0 {
podEvent.Put("cpu.usage.limit.pct", float64(usageNanoCores)/1e9/coresLimit)
}

if memLimit > 0 {
podEvent.Put("memory.usage.limit.pct", float64(usageMem)/memLimit)
if usageMem > 0 {
if nodeMem > 0 {
podEvent.Put("memory.usage.node.pct", float64(usageMem)/nodeMem)
}
if memLimit > 0 {
podEvent.Put("memory.usage.limit.pct", float64(usageMem)/memLimit)
}
}

if workingSet > 0 && usageMem == 0 {
if nodeMem > 0 {
podEvent.Put("memory.usage.node.pct", float64(workingSet)/nodeMem)
}
if memLimit > 0 {
podEvent.Put("memory.usage.limit.pct", float64(workingSet)/memLimit)
}
}

events = append(events, podEvent)
Expand Down

0 comments on commit 741ca40

Please sign in to comment.