Skip to content

Commit

Permalink
Add cgroup_memory_migrate metric
Browse files Browse the repository at this point in the history
Signed-off-by: Wisniewski, Krzysztof2 <[email protected]>
  • Loading branch information
kwisniewski98 committed Feb 17, 2021
1 parent 730e7df commit bc8b918
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions container/libcontainer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ func setMemoryStats(s *cgroups.Stats, ret *info.ContainerStats) {
ret.Memory.Usage = s.MemoryStats.Usage.Usage
ret.Memory.MaxUsage = s.MemoryStats.Usage.MaxUsage
ret.Memory.Failcnt = s.MemoryStats.Usage.Failcnt
ret.CpuSet.MemoryMigrate = s.CPUSetStats.MemoryMigrate

if s.MemoryStats.UseHierarchy {
ret.Memory.Cache = s.MemoryStats.Stats["total_cache"]
Expand Down
1 change: 1 addition & 0 deletions docs/storage/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Metric name | Type | Description | Unit (where applicable) | -disable_metrics pa
`container_memory_rss` | Gauge | Size of RSS | bytes | |
`container_memory_swap` | Gauge | Container swap usage | bytes | |
`container_memory_mapped_file` | Gauge | Size of memory mapped files | bytes | |
`container_memory_migrate` | Gauge | Memory migrate status | | memory |
`container_memory_usage_bytes` | Gauge | Current memory usage, including all memory regardless of when it was accessed | bytes | |
`container_memory_working_set_bytes` | Gauge | Current working set | bytes | |
`container_network_receive_bytes_total` | Counter | Cumulative count of bytes received | bytes | network |
Expand Down
6 changes: 6 additions & 0 deletions info/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ type MemoryStats struct {
HierarchicalData MemoryStatsMemoryData `json:"hierarchical_data,omitempty"`
}

type CPUSetStats struct {
MemoryMigrate uint64 `json:"memory_migrate"`
}

type MemoryNumaStats struct {
File map[uint8]uint64 `json:"file,omitempty"`
Anon map[uint8]uint64 `json:"anon,omitempty"`
Expand Down Expand Up @@ -957,6 +961,8 @@ type ContainerStats struct {

// Resource Control (resctrl) statistics
Resctrl ResctrlStats `json:"resctrl,omitempty"`

CpuSet CPUSetStats `json:"cpuset,omitempty"`
}

func timeEq(t1, t2 time.Time, tolerance time.Duration) bool {
Expand Down
8 changes: 8 additions & 0 deletions metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
return metricValues{{value: float64(s.Memory.WorkingSet), timestamp: s.Timestamp}}
},
},
{
name: "container_memory_migrate",
help: "Memory migrate status.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.CpuSet.MemoryMigrate), timestamp: s.Timestamp}}
},
},
{
name: "container_memory_failures_total",
help: "Cumulative count of memory allocation failures.",
Expand Down
1 change: 1 addition & 0 deletions metrics/prometheus_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ func (p testSubcontainersInfoProvider) GetRequestedContainersInfo(string, v2.Req
},
},
},
CpuSet: info.CPUSetStats{MemoryMigrate: 1},
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions metrics/testdata/prometheus_metrics
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ container_memory_mapped_file{container_env_foo_env="prod",container_label_foo_la
# HELP container_memory_max_usage_bytes Maximum memory usage recorded in bytes
# TYPE container_memory_max_usage_bytes gauge
container_memory_max_usage_bytes{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 8 1395066363000
# HELP container_memory_migrate Memory migrate status.
# TYPE container_memory_migrate gauge
container_memory_migrate{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 1 1395066363000
# HELP container_memory_numa_pages Number of used pages per NUMA node
# TYPE container_memory_numa_pages gauge
container_memory_numa_pages{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",node="0",scope="container",type="anon",zone_name="hello"} 10000 1395066363000
Expand Down

0 comments on commit bc8b918

Please sign in to comment.