Documentation
¶
Overview ¶
Package memusage logs Linux process and container memory high-water marks. Accounting is read on each call; no background sampling or shared state is used. Log is safe for concurrent use.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Log ¶
Log records Linux kernel memory high-water marks with the context logger. Missing or unsupported accounting is logged as null with an error, not zero. The process RSS excludes children and unmapped tmpfs; the cgroup peak includes all memory charged to the container, including child processes and scratch files. These are lifetime peaks, not per-call measurements. Log is safe for concurrent use.
Types ¶
type Container ¶ added in v1.56.0
type Container struct {
// Current is the memory charged to the container now: cgroup v2
// memory.current or v1 memory.usage_in_bytes.
Current *uint64
CurrentErr error
// Limit is the memory limit: cgroup v2 memory.max or v1
// memory.limit_in_bytes. A v2 limit of "max" is unknown.
Limit *uint64
LimitErr error
// Peak is the lifetime high-water mark: cgroup v2 memory.peak or v1
// memory.max_usage_in_bytes. It only rises, so it shows how close the
// container came to its limit even between samples.
Peak *uint64
PeakErr error
}
Container is a snapshot of the container cgroup's memory accounting, read from the controller mounted at the current process's root. A nil value is unknown, and its error says why; it is never reported as zero.
func ReadContainer ¶ added in v1.56.0
func ReadContainer() Container
ReadContainer reads the container cgroup's current usage, limit, and lifetime peak. Each read is bounded and verified as Log's peak read is.