cgroups

package
v0.1.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cgroups reads cgroup v2 statistics directly from the filesystem, per the plan (the agent reads cgroup v2 stats directly rather than shelling out). It reports memory, CPU and egress usage for a container's cgroup.

Egress is read for observability only. It is never used to cap or bill traffic, since egress is unmetered on every tier. There is no egress cap anywhere in the agent.

Reads are defensive: a missing file or an unreadable cgroup yields a zero value for that field rather than an error, so a single unreadable stat never fails the whole host status report. This package is Linux-oriented (cgroup v2 lives under /sys/fs/cgroup), but it compiles and returns zeroes elsewhere so the agent builds on any platform for local development.

Index

Constants

View Source
const DefaultRoot = "/sys/fs/cgroup"

DefaultRoot is the standard cgroup v2 unified hierarchy mount point.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads cgroup v2 stats from a filesystem root. It carries a small amount of state so CPU usage can be reported as a fraction of a core between two samples.

func NewReader

func NewReader() *Reader

NewReader constructs a stats reader.

func (*Reader) Usage

func (r *Reader) Usage(cgroupPath string, wallNow int64) contract.CgroupUsage

Usage reads memory, CPU and egress for the cgroup at cgroupPath, using wallNow (nanoseconds, monotonic) to compute the CPU fraction against the previous sample. The first sample for a path reports a CPU fraction of zero because there is no prior point to difference against.

A blank cgroupPath (for example when the container's cgroup could not be resolved) returns a zero-valued usage without error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL