fix(clistat): do not include buffers/cache for host memory used (#8095)

This commit is contained in:
Cian Johnston
2023-06-20 13:29:27 +01:00
committed by GitHub
parent 06a5e24f5b
commit 0f754f0bb9
+5 -1
View File
@@ -186,6 +186,10 @@ func (s *Statter) HostMemory() (*Result, error) {
return nil, xerrors.Errorf("get memory info: %w", err)
}
r.Total = ptr.To(float64(hm.Total))
r.Used = float64(hm.Used)
// On Linux, hm.Used equates to MemTotal - MemFree in /proc/stat.
// This includes buffers and cache.
// So use MemAvailable instead, which only equates to physical memory.
// On Windows, this is also calculated as Total - Available.
r.Used = float64(hm.Total - hm.Available)
return r, nil
}