Fix get container mem usage (#10796)

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
bigsheeper 2021-10-28 14:22:23 +08:00 committed by GitHub
parent b5fc643efd
commit 9a0d1d1e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,5 +57,11 @@ func GetContainerMemUsed() (uint64, error) {
if stats.Memory == nil || stats.Memory.Usage == nil {
return 0, errors.New("cannot find memory usage info from cGroups")
}
return stats.Memory.Usage.Usage, nil
// ref: <https://github.com/docker/cli/blob/e57b5f78de635e6e2b688686d10b830c4747c4dc/cli/command/container/stats_helpers.go#L239>
inactiveFile := stats.Memory.InactiveFile
usage := stats.Memory.Usage.Usage
if inactiveFile < usage {
return usage - inactiveFile, nil
}
return usage, nil
}