Skip to content

Commit

Permalink
Fix the way memory RSS is calculated for cgroupv2 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock authored Dec 30, 2024
1 parent db27169 commit fa37ac5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion collector/cgroupv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (e *Exporter) getMetricsv2(name string, pids []int, opts cgroup2.InitOpts)
return metric, err
}
if stats.Memory != nil {
metric.memoryRSS = float64(stats.Memory.Anon) + swapcached + float64(stats.Memory.AnonThp)
metric.memoryRSS = float64(stats.Memory.Anon) + swapcached + float64(stats.Memory.File)
metric.memoryUsed = float64(stats.Memory.Usage)
metric.memoryTotal = float64(stats.Memory.UsageLimit)
metric.memoryCache = float64(stats.Memory.File)
Expand Down
4 changes: 2 additions & 2 deletions collector/cgroupv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestCollectv2UserSlice(t *testing.T) {
if val := metrics[0].cpus; val != 0 {
t.Errorf("Unexpected value for cpus, got %v", val)
}
if val := metrics[0].memoryRSS; val != 22048768 {
if val := metrics[0].memoryRSS; val != 22626304 {
t.Errorf("Unexpected value for memoryRSS, got %v", val)
}
if val := metrics[0].memoryUsed; val != 27115520 {
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestCollectv2SLURM(t *testing.T) {
if val := m.cpus; val != 1 {
t.Errorf("Unexpected value for cpus, got %v", val)
}
if val := m.memoryRSS; val != 2260992 {
if val := m.memoryRSS; val != 2777088 {
t.Errorf("Unexpected value for memoryRSS, got %v", val)
}
if val := m.memoryUsed; val != 5660672 {
Expand Down

0 comments on commit fa37ac5

Please sign in to comment.