diff --git a/container/libcontainer/handler.go b/container/libcontainer/handler.go index cb34177cb9..e101811ef0 100644 --- a/container/libcontainer/handler.go +++ b/container/libcontainer/handler.go @@ -828,6 +828,20 @@ func setMemoryStats(s *cgroups.Stats, ret *info.ContainerStats) { ret.Memory.HierarchicalData.Pgmajfault = v } + inactiveAnonKeyName := "total_inactive_anon" + activeAnonKeyName := "total_active_anon" + if cgroups.IsCgroup2UnifiedMode() { + inactiveAnonKeyName = "inactive_anon" + activeAnonKeyName = "active_anon" + } + + if v, ok := s.MemoryStats.Stats[activeAnonKeyName]; ok { + ret.Memory.TotalActiveAnon = v + } + if v, ok := s.MemoryStats.Stats[inactiveAnonKeyName]; ok { + ret.Memory.TotalInactiveAnon = v + } + inactiveFileKeyName := "total_inactive_file" if cgroups.IsCgroup2UnifiedMode() { inactiveFileKeyName = "inactive_file" diff --git a/info/v1/container.go b/info/v1/container.go index 5921783165..9aa6cac8fb 100644 --- a/info/v1/container.go +++ b/info/v1/container.go @@ -425,6 +425,14 @@ type MemoryStats struct { // Units: Bytes. TotalInactiveFile uint64 `json:"total_inactive_file"` + // The total amount of active anonymous memory. + // Units: Bytes. + TotalActiveAnon uint64 `json:"total_active_anon"` + + // The total amount of inactive anonymous memory. + // Units: Bytes. + TotalInactiveAnon uint64 `json:"total_inactive_anon"` + Failcnt uint64 `json:"failcnt"` // Size of kernel memory allocated in bytes. diff --git a/metrics/prometheus.go b/metrics/prometheus.go index aa6d53ceeb..394a46dc9b 100644 --- a/metrics/prometheus.go +++ b/metrics/prometheus.go @@ -443,6 +443,22 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri return metricValues{{value: float64(s.Memory.WorkingSet), timestamp: s.Timestamp}} }, }, + { + name: "container_memory_total_inactive_anon_bytes", + help: "Current total inactive anonymous in bytes.", + valueType: prometheus.GaugeValue, + getValues: func(s *info.ContainerStats) metricValues { + return metricValues{{value: float64(s.Memory.TotalInactiveAnon), timestamp: s.Timestamp}} + }, + }, + { + name: "container_memory_total_active_anon_bytes", + help: "Current total active anonymous in bytes.", + valueType: prometheus.GaugeValue, + getValues: func(s *info.ContainerStats) metricValues { + return metricValues{{value: float64(s.Memory.TotalActiveAnon), timestamp: s.Timestamp}} + }, + }, { name: "container_memory_total_active_file_bytes", help: "Current total active file in bytes.", @@ -459,6 +475,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri return metricValues{{value: float64(s.Memory.TotalInactiveFile), timestamp: s.Timestamp}} }, }, + { name: "container_memory_failures_total", help: "Cumulative count of memory allocation failures.",