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
In Windows native containers usage memory is reported
using the workingSet. Use this value to calculate memory
usage percentage.

(cherry picked from commit 381e062)
  • Loading branch information
brianharwell authored and mergify-bot committed Apr 30, 2021
1 parent 3f77cb1 commit 95e30e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ 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 95e30e5

Please sign in to comment.