From 54ff378aca4b6b45c05230372fdda36a2db837bc Mon Sep 17 00:00:00 2001 From: Brian Harwell Date: Fri, 30 Apr 2021 13:21:09 -0400 Subject: [PATCH] Calculate memory usage percentage in Windows kubernetes pods (#25428) In Windows native containers usage memory is reported using the workingSet. Use this value to calculate memory usage percentage. (cherry picked from commit 381e06269607484c3ef5b670653d924d588b244d) --- CHANGELOG.next.asciidoc | 2 ++ metricbeat/module/kubernetes/pod/data.go | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index ff47cbcd8ed..d75084e678d 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -330,6 +330,8 @@ 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* diff --git a/metricbeat/module/kubernetes/pod/data.go b/metricbeat/module/kubernetes/pod/data.go index 306ba1c06b3..bb24d31905c 100644 --- a/metricbeat/module/kubernetes/pod/data.go +++ b/metricbeat/module/kubernetes/pod/data.go @@ -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)