Skip to content

Commit

Permalink
Add remaining memory metrics of pods in Kubernetes metricbeat module (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel authored and exekias committed Jan 21, 2019
1 parent f6ed58c commit e14225c
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add `nats` module with `stats` metricset. {pull}9825[9825]
- Add `connections` metricset to the `nats` module. {pull}10095[10095]
- Add `routes` metricset to the `nats` module. {pull}10095[10095]
- Add remaining memory metrics of pods in Kubernetes metricbeat module {pull}10157[10157]

*Packetbeat*

Expand Down
59 changes: 59 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11858,6 +11858,65 @@ format: percentage
Memory usage as a percentage of the defined limit for the pod containers (or total node allocatable memory if unlimited)
--
*`kubernetes.pod.memory.available.bytes`*::
+
--
type: long
format: bytes
Total memory available
--
*`kubernetes.pod.memory.workingSet.bytes`*::
+
--
type: long
format: bytes
Total working set memory
--
*`kubernetes.pod.memory.rss.bytes`*::
+
--
type: long
format: bytes
Total resident set size memory
--
*`kubernetes.pod.memory.pageFaults`*::
+
--
type: long
Total page faults
--
*`kubernetes.pod.memory.majorPageFaults`*::
+
--
type: long
Total major page faults
--
[float]
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/kubernetes/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package event
import (
"testing"

"github.com/ericchiang/k8s/apis/core/v1"
v1 "github.com/ericchiang/k8s/apis/core/v1"
k8s_io_apimachinery_pkg_apis_meta_v1 "github.com/ericchiang/k8s/apis/meta/v1"
"github.com/stretchr/testify/assert"

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/kubernetes/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions metricbeat/module/kubernetes/pod/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,35 @@
format: percentage
description: >
Memory usage as a percentage of the defined limit for the pod containers (or total node allocatable memory if unlimited)
- name: available
type: group
fields:
- name: bytes
type: long
format: bytes
description: >
Total memory available
- name: workingSet
type: group
fields:
- name: bytes
type: long
format: bytes
description: >
Total working set memory
- name: rss
type: group
fields:
- name: bytes
type: long
format: bytes
description: >
Total resident set size memory
- name: pageFaults
type: long
description: >
Total page faults
- name: majorPageFaults
type: long
description: >
Total major page faults
21 changes: 19 additions & 2 deletions metricbeat/module/kubernetes/pod/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@ func eventMapping(content []byte, perfMetrics *util.PerfMetricsCache) ([]common.
var summary kubernetes.Summary
err := json.Unmarshal(content, &summary)
if err != nil {
return nil, fmt.Errorf("Cannot unmarshal json response: %s", err)
return nil, fmt.Errorf("cannot unmarshal json response: %s", err)
}

node := summary.Node
nodeCores := perfMetrics.NodeCoresAllocatable.Get(node.NodeName)
nodeMem := perfMetrics.NodeMemAllocatable.Get(node.NodeName)
for _, pod := range summary.Pods {
var usageNanoCores, usageMem int64
var usageNanoCores, usageMem, availMem, rss, workingSet, pageFaults, majorPageFaults int64
var coresLimit, memLimit float64

for _, cont := range pod.Containers {
cuid := util.ContainerUID(pod.PodRef.Namespace, pod.PodRef.Name, cont.Name)
usageNanoCores += cont.CPU.UsageNanoCores
usageMem += cont.Memory.UsageBytes
availMem += cont.Memory.AvailableBytes
rss += cont.Memory.RssBytes
workingSet += cont.Memory.WorkingSetBytes
pageFaults += cont.Memory.PageFaults
majorPageFaults += cont.Memory.MajorPageFaults

coresLimit += perfMetrics.ContainerCoresLimit.GetWithDefault(cuid, nodeCores)
memLimit += perfMetrics.ContainerMemLimit.GetWithDefault(cuid, nodeMem)
}
Expand All @@ -70,6 +76,17 @@ func eventMapping(content []byte, perfMetrics *util.PerfMetricsCache) ([]common.
"usage": common.MapStr{
"bytes": usageMem,
},
"available": common.MapStr{
"bytes": availMem,
},
"workingSet": common.MapStr{
"bytes": workingSet,
},
"rss": common.MapStr{
"bytes": rss,
},
"pageFaults": pageFaults,
"majorPageFaults": majorPageFaults,
},

"network": common.MapStr{
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/kubernetes/util/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package util
import (
"testing"

"github.com/ericchiang/k8s/apis/meta/v1"
v1 "github.com/ericchiang/k8s/apis/meta/v1"
"github.com/stretchr/testify/assert"

"github.com/elastic/beats/libbeat/common"
Expand Down

0 comments on commit e14225c

Please sign in to comment.