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
…#25473)

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 authored May 5, 2021
1 parent 19330b2 commit 6fd41ad
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 @@ -332,6 +332,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix type of `uwsgi.status.worker.rss` type. {pull}24468[24468]
- Ignore unsupported derive types for filesystem metricset. {issue}22501[22501] {pull}24502[24502]
- 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 6fd41ad

Please sign in to comment.