Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: group memory.stats sock metric #3642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/internal/storage/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const (
serMemorySwap string = "memory_swap"
// Size of memory mapped files in bytes
serMemoryMappedFile string = "memory_mapped_file"
// Size of socket memory in bytes
serMemorySocket string = "memory_socket"
// Working set size
serMemoryWorkingSet string = "memory_working_set"
// Total active file size
Expand Down Expand Up @@ -258,6 +260,8 @@ func (s *influxdbStorage) memoryStatsToPoints(
points = append(points, makePoint(serMemorySwap, stats.Memory.Swap))
// Size of memory mapped files in bytes
points = append(points, makePoint(serMemoryMappedFile, stats.Memory.MappedFile))
// Size of socket memory in bytes
points = append(points, makePoint(serMemorySocket, stats.Memory.Socket))
// Working Set Size
points = append(points, makePoint(serMemoryWorkingSet, stats.Memory.WorkingSet))
// Total Active File Size
Expand Down
2 changes: 2 additions & 0 deletions cmd/internal/storage/influxdb/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func TestContainerStatsToPoints(t *testing.T) {
assertContainsPointWithValue(t, points, serMemoryRss, stats.Memory.RSS)
assertContainsPointWithValue(t, points, serMemorySwap, stats.Memory.Swap)
assertContainsPointWithValue(t, points, serMemoryMappedFile, stats.Memory.MappedFile)
assertContainsPointWithValue(t, points, serMemorySocket, stats.Memory.Socket)
assertContainsPointWithValue(t, points, serMemoryUsage, stats.Memory.Usage)
assertContainsPointWithValue(t, points, serMemoryWorkingSet, stats.Memory.WorkingSet)
assertContainsPointWithValue(t, points, serMemoryTotalActiveFile, stats.Memory.TotalActiveFile)
Expand Down Expand Up @@ -362,6 +363,7 @@ func createTestStats() (*info.ContainerInfo, *info.ContainerStats) {
RSS: 18930020352,
Swap: 1024,
MappedFile: 1025327104,
Socket: 1025327104,
WorkingSet: 23630012416,
TotalActiveFile: 29459246253,
TotalInactiveFile: 28364536434,
Expand Down
4 changes: 4 additions & 0 deletions cmd/internal/storage/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const (
serMemorySwap string = "memory_swap"
// Size of memory mapped files in bytes
serMemoryMappedFile string = "memory_mapped_file"
// Size of socket memory in bytes
serMemorySocket string = "memory_socket"
// Working set size
serMemoryWorkingSet string = "memory_working_set"
// Total active file size
Expand Down Expand Up @@ -161,6 +163,8 @@ func (s *statsdStorage) memoryStatsToValues(series *map[string]uint64, stats *in
(*series)[serMemorySwap] = stats.Memory.Swap
// Size of memory mapped files in bytes
(*series)[serMemoryMappedFile] = stats.Memory.MappedFile
// Size of socket memory in bytes.
(*series)[serMemorySocket] = stats.Memory.Socket
// Working Set Size
(*series)[serMemoryWorkingSet] = stats.Memory.WorkingSet
// Total Active File Size
Expand Down
4 changes: 4 additions & 0 deletions cmd/internal/storage/stdout/stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
serMemorySwap string = "memory_swap"
// Size of memory mapped files in bytes
serMemoryMappedFile string = "memory_mapped_file"
// Size of socket memory in bytes
serMemorySocket string = "memory_socket"
// Working set size
serMemoryWorkingSet string = "memory_working_set"
// Total active file
Expand Down Expand Up @@ -166,6 +168,8 @@ func (driver *stdoutStorage) memoryStatsToValues(series *map[string]uint64, stat
(*series)[serMemorySwap] = stats.Memory.Swap
// Size of memory mapped files in bytes
(*series)[serMemoryMappedFile] = stats.Memory.MappedFile
// Size of socket memory in bytes
(*series)[serMemorySocket] = stats.Memory.Socket
// Working Set Size
(*series)[serMemoryWorkingSet] = stats.Memory.WorkingSet
// Total Active File
Expand Down
2 changes: 2 additions & 0 deletions container/libcontainer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,8 @@ func setMemoryStats(s *cgroups.Stats, ret *info.ContainerStats) {
ret.Memory.MaxUsage = s.MemoryStats.Usage.MaxUsage
ret.Memory.Failcnt = s.MemoryStats.Usage.Failcnt
ret.Memory.KernelUsage = s.MemoryStats.KernelUsage.Usage
ret.Memory.Socket = s.MemoryStats.Stats["sock"]
fmt.Println(s.MemoryStats.Stats)

if cgroups.IsCgroup2UnifiedMode() {
ret.Memory.Cache = s.MemoryStats.Stats["file"]
Expand Down
4 changes: 4 additions & 0 deletions info/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ type MemoryStats struct {
// The amount of memory used for mapped files (includes tmpfs/shmem)
MappedFile uint64 `json:"mapped_file"`

// The amount of kernel memory used by the sockets spawned by the process.
// Units: Bytes.
Socket uint64 `json:"socket"`

// The amount of working set memory, this includes recently accessed memory,
// dirty memory, and kernel memory. Working set is <= "usage".
// Units: Bytes.
Expand Down
1 change: 1 addition & 0 deletions info/v1/test/datagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func GenerateRandomStats(numStats, numCores int, duration time.Duration) []*info
stats.Memory.Cache = uint64(rand.Int63n(4096))
stats.Memory.RSS = uint64(rand.Int63n(4096))
stats.Memory.MappedFile = uint64(rand.Int63n(4096))
stats.Memory.Socket = uint64(rand.Int63n(4096))
stats.Memory.KernelUsage = uint64(rand.Int63n(4096))
stats.ReferencedMemory = uint64(rand.Int63n(1000))
ret[i] = stats
Expand Down
7 changes: 7 additions & 0 deletions metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.MappedFile), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_socket",
help: "Size of kernel memory allocated by sockets.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.Socket), timestamp: s.Timestamp}}
},
}, {
name: "container_memory_swap",
help: "Container swap usage in bytes.",
Expand Down
1 change: 1 addition & 0 deletions metrics/prometheus_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func (p testSubcontainersInfoProvider) GetRequestedContainersInfo(string, v2.Req
Cache: 14,
RSS: 15,
MappedFile: 16,
Socket: 16,
KernelUsage: 17,
Swap: 8192,
},
Expand Down