diff --git a/command/alloc_status.go b/command/alloc_status.go index 4e21d18adff..b9d2b46be5c 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -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 } diff --git a/command/helpers.go b/command/helpers.go index 74b221bba40..177cf48c17c 100644 --- a/command/helpers.go +++ b/command/helpers.go @@ -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 +}