fix(mem): 修正 Linux 内存使用计算方法

- 更新内存使用计算公式,参考 psutil 项目中的实现
- 考虑 Buff/Cache 实际上也被使用的情况
- 修改 Used 字段的计算方式,从 Total 中减去 Free,不再减去 Buffers 和 Cached
pull/1824/head
liang.che 2 months ago
parent d18573cbf1
commit cca4501c14

@ -303,8 +303,9 @@ func fillFromMeminfoWithContext(ctx context.Context) (*VirtualMemoryStat, *ExVir
ret.Available = ret.Cached + ret.Free
}
}
ret.Used = ret.Total - ret.Free - ret.Buffers - ret.Cached
//https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L175
// Buff/Cache is actually being used
ret.Used = ret.Total - ret.Free
ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0
return ret, retEx, nil

Loading…
Cancel
Save