Skip to content

Commit 8cdffd7

Browse files
committed
ft/export-memory-kernal-usage
1 parent 2e4a919 commit 8cdffd7

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

container/libcontainer/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ func setMemoryStats(s *cgroups.Stats, ret *info.ContainerStats) {
802802
ret.Memory.Usage = s.MemoryStats.Usage.Usage
803803
ret.Memory.MaxUsage = s.MemoryStats.Usage.MaxUsage
804804
ret.Memory.Failcnt = s.MemoryStats.Usage.Failcnt
805+
ret.Memory.Kernel = s.MemoryStats.KernelUsage.Usage
805806

806807
if cgroups.IsCgroup2UnifiedMode() {
807808
ret.Memory.Cache = s.MemoryStats.Stats["file"]

info/v1/container.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ type MemoryStats struct {
395395

396396
Failcnt uint64 `json:"failcnt"`
397397

398+
// Size of kernel memory allocated in bytes.
399+
// Units: Bytes.
400+
Kernel uint64 `json:"kernel"`
401+
398402
ContainerData MemoryStatsMemoryData `json:"container_data,omitempty"`
399403
HierarchicalData MemoryStatsMemoryData `json:"hierarchical_data,omitempty"`
400404
}

info/v1/test/datagen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func GenerateRandomStats(numStats, numCores int, duration time.Duration) []*info
4747
stats.Memory.Cache = uint64(rand.Int63n(4096))
4848
stats.Memory.RSS = uint64(rand.Int63n(4096))
4949
stats.Memory.MappedFile = uint64(rand.Int63n(4096))
50+
stats.Memory.Kernel = uint64(rand.Int63n(4096))
5051
stats.ReferencedMemory = uint64(rand.Int63n(1000))
5152
ret[i] = stats
5253
}

metrics/prometheus.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
378378
return metricValues{{value: float64(s.Memory.RSS), timestamp: s.Timestamp}}
379379
},
380380
}, {
381+
name: "container_memory_kernel",
382+
help: "Size of kernel memory allocated in bytes.",
383+
valueType: prometheus.GaugeValue,
384+
getValues: func(s *info.ContainerStats) metricValues {
385+
return metricValues{{value: float64(s.Memory.Kernel), timestamp: s.Timestamp}}
386+
},
387+
},{
381388
name: "container_memory_mapped_file",
382389
help: "Size of memory mapped files in bytes.",
383390
valueType: prometheus.GaugeValue,

metrics/prometheus_fake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ func (p testSubcontainersInfoProvider) GetRequestedContainersInfo(string, v2.Req
353353
Cache: 14,
354354
RSS: 15,
355355
MappedFile: 16,
356+
Kernel: 17,
356357
Swap: 8192,
357358
},
358359
Hugetlb: map[string]info.HugetlbStats{

metrics/testdata/prometheus_metrics

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ container_memory_failures_total{container_env_foo_env="prod",container_label_foo
148148
container_memory_failures_total{container_env_foo_env="prod",container_label_foo_label="bar",failure_type="pgfault",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",zone_name="hello"} 12 1395066363000
149149
container_memory_failures_total{container_env_foo_env="prod",container_label_foo_label="bar",failure_type="pgmajfault",id="testcontainer",image="test",name="testcontaineralias",scope="container",zone_name="hello"} 11 1395066363000
150150
container_memory_failures_total{container_env_foo_env="prod",container_label_foo_label="bar",failure_type="pgmajfault",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",zone_name="hello"} 13 1395066363000
151+
# HELP container_memory_kernel Size of kernel memory allocated in bytes.
152+
# TYPE container_memory_kernel gauge
153+
container_memory_kernel{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 17 1395066363000
151154
# HELP container_memory_mapped_file Size of memory mapped files in bytes.
152155
# TYPE container_memory_mapped_file gauge
153156
container_memory_mapped_file{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 16 1395066363000

0 commit comments

Comments
 (0)