Skip to content

Commit

Permalink
cli: Show memory usage instead of RSS
Browse files Browse the repository at this point in the history
If a task doesn't report RSS, let's use memory usage.
  • Loading branch information
Mahmood Ali committed Apr 2, 2021
1 parent f7b7b1c commit f14921d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,13 @@ func (c *AllocStatusCommand) outputTaskResources(alloc *api.Allocation, task str
cpuUsage = fmt.Sprintf("%v/%v", math.Floor(cs.TotalTicks), cpuUsage)
}
if ms := ru.ResourceUsage.MemoryStats; ms != nil {
memUsage = fmt.Sprintf("%v/%v", humanize.IBytes(ms.RSS), memUsage)
// Nomad uses RSS as the top-level metric to report, for historical reasons,
// but it's not always measured (e.g. with cgroup-v2)
usage := ms.RSS
if usage == 0 && !stringsContain(ms.Measured, "RSS") {
usage = ms.Usage
}
memUsage = fmt.Sprintf("%v/%v", humanize.IBytes(usage), memUsage)
}
deviceStats = ru.ResourceUsage.DeviceStats
}
Expand Down
11 changes: 11 additions & 0 deletions command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,14 @@ func (w *uiErrorWriter) Close() error {
}
return nil
}

// stringsContains returns true if s is present in the vs string slice
func stringsContain(vs []string, s string) bool {
for _, v := range vs {
if v == s {
return true
}
}

return false
}

0 comments on commit f14921d

Please sign in to comment.