cli: Show memory usage instead of RSS

If a task doesn't report RSS, let's use memory usage.
This commit is contained in:
Mahmood Ali
2021-04-01 11:56:23 -04:00
parent f7b7b1cf3f
commit f14921d41d
2 changed files with 18 additions and 1 deletions

View File

@@ -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
}

View File

@@ -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
}