Go语言 MemoryStats 结构体详解:理解容器内存使用情况
Go语言 MemoryStats 结构体详解:理解容器内存使用情况
MemoryStats 结构体用于聚合容器自启动以来的所有内存统计信息。本文将详细解释每个字段的含义,并区分 Linux 和 Windows 平台上的差异,帮助您更好地理解容器内存使用情况。go// MemoryStats aggregates all memory stats since container inception on Linux.// Windows returns stats for commit and private working set only.type MemoryStats struct { // Linux Memory Stats
// current res_counter usage for memory Usage uint64 `json:'usage,omitempty'` // maximum usage ever recorded. MaxUsage uint64 `json:'max_usage,omitempty'` // TODO(vishh): Export these as stronger types. // all the stats exported via memory.stat. Stats map[string]uint64 `json:'stats,omitempty'` // number of times memory usage hits limits. Failcnt uint64 `json:'failcnt,omitempty'` Limit uint64 `json:'limit,omitempty'`
// Windows Memory Stats // See https://technet.microsoft.com/en-us/magazine/ff382715.aspx
// committed bytes Commit uint64 `json:'commitbytes,omitempty'` // peak committed bytes CommitPeak uint64 `json:'commitpeakbytes,omitempty'` // private working set PrivateWorkingSet uint64 `json:'privateworkingset,omitempty'`}
Linux 平台
- Usage: 当前内存使用量。- MaxUsage: 历史最大内存使用量。- Stats: 通过
memory.stat导出的所有统计信息,例如缓存、缓冲区、匿名和文件映射等。- Failcnt: 内存使用超过限制的次数。- Limit: 内存限制大小。
Windows 平台
- Commit: 已提交的字节数。- CommitPeak: 峰值已提交的字节数。- PrivateWorkingSet: 私有工作集字节数。
获取容器内存使用情况
- 容器当前使用的内存大小: - Linux:
Usage字段 - Windows:PrivateWorkingSet字段- 容器的所有内存大小: - Linux:MaxUsage字段 - Windows:CommitPeak字段
通过 MemoryStats 结构体,我们可以全面了解容器的内存使用情况,并根据实际需求进行监控和管理。
原文地址: https://www.cveoy.top/t/topic/fyS0 著作权归作者所有。请勿转载和采集!