import "github.com/containerd/cgroups"
blkio.go cgroup.go control.go cpu.go cpuacct.go cpuset.go devices.go errors.go freezer.go hierarchy.go hugetlb.go memory.go named.go net_cls.go net_prio.go opts.go paths.go perf_event.go pids.go rdma.go state.go subsystem.go systemd.go ticks.go utils.go v1.go
var ( ErrInvalidPid = errors.New("cgroups: pid must be greater than 0") ErrMountPointNotExist = errors.New("cgroups: cgroup mountpoint does not exist") ErrInvalidFormat = errors.New("cgroups: parsing file with invalid format failed") ErrFreezerNotSupported = errors.New("cgroups: freezer cgroup not supported on this system") ErrMemoryNotSupported = errors.New("cgroups: memory cgroup not supported on this system") ErrCgroupDeleted = errors.New("cgroups: cgroup deleted") ErrNoCgroupMountDestination = errors.New("cgroups: cannot find cgroup mount destination") )
var ( // ErrIgnoreSubsystem allows the specific subsystem to be skipped ErrIgnoreSubsystem = errors.New("skip subsystem") // ErrDevicesRequired is returned when the devices subsystem is required but // does not exist or is not active ErrDevicesRequired = errors.New("devices subsystem is required") )
ErrControllerNotActive is returned when a controller is not supported or enabled
AllowAny allows any subsystem errors to be skipped
IgnoreModules configure the memory controller to not read memory metrics for some module names (e.g. passing "memsw" would avoid all the memory.memsw.* entries)
IgnoreNotExist ignores any errors that are for not existing files
NewBlkio returns a Blkio controller given the root folder of cgroups. It may optionally accept other configuration options, such as ProcRoot(path)
NewMemory returns a Memory controller given the root folder of cgroups. It may optionally accept other configuration options, such as IgnoreModules(...)
func OptionalSwap() func(*memoryController)
OptionalSwap allows the memory controller to not fail if cgroups is not accounting Swap memory (there are no memory.memsw.* entries)
ProcRoot overrides the default location of the "/proc" filesystem
RequireDevices requires the device subsystem but no others
CGMode is the cgroups mode of the host system
const ( // Unavailable cgroup mountpoint CGMode = iota // Legacy cgroups v1 Legacy // Hybrid with cgroups v1 and v2 controllers mounted Hybrid // Unified with only cgroups v2 mounted Unified )
Mode returns the cgroups mode running on the host
type Cgroup interface { // New creates a new cgroup under the calling cgroup New(string, *specs.LinuxResources) (Cgroup, error) // Add adds a process to the cgroup (cgroup.procs) Add(Process) error // AddTask adds a process to the cgroup (tasks) AddTask(Process) error // Delete removes the cgroup as a whole Delete() error // MoveTo moves all the processes under the calling cgroup to the provided one // subsystems are moved one at a time MoveTo(Cgroup) error // Stat returns the stats for all subsystems in the cgroup Stat(...ErrorHandler) (*v1.Metrics, error) // Update updates all the subsystems with the provided resource changes Update(resources *specs.LinuxResources) error // Processes returns all the processes in a select subsystem for the cgroup Processes(Name, bool) ([]Process, error) // Tasks returns all the tasks in a select subsystem for the cgroup Tasks(Name, bool) ([]Task, error) // Freeze freezes or pauses all processes inside the cgroup Freeze() error // Thaw thaw or resumes all processes inside the cgroup Thaw() error // OOMEventFD returns the memory subsystem's event fd for OOM events OOMEventFD() (uintptr, error) // State returns the cgroups current state State() State // Subsystems returns all the subsystems in the cgroup Subsystems() []Subsystem }
Cgroup handles interactions with the individual groups to perform actions on them as them main interface to this cgroup package
Load will load an existing cgroup and allow it to be controlled All static path should not include `/sys/fs/cgroup/` prefix, it should start with your own cgroups name
func New(hierarchy Hierarchy, path Path, resources *specs.LinuxResources, opts ...InitOpts) (Cgroup, error)
New returns a new control via the cgroup cgroups interface
ErrorHandler is a function that handles and acts on errors
Hierarchy enableds both unified and split hierarchy for cgroups
SingleSubsystem returns a single cgroup subsystem within the base Hierarchy
InitCheck allows subsystems errors to be checked when initialized or loaded
type InitConfig struct { // InitCheck can be used to check initialization errors from the subsystem InitCheck InitCheck }
InitConfig provides configuration options for the creation or loading of a cgroup and its subsystems
type InitOpts func(*InitConfig) error
InitOpts allows configuration for the creation or loading of a cgroup
Name is a typed name for a cgroup subsystem
const ( Devices Name = "devices" Hugetlb Name = "hugetlb" Freezer Name = "freezer" Pids Name = "pids" NetCLS Name = "net_cls" NetPrio Name = "net_prio" PerfEvent Name = "perf_event" Cpuset Name = "cpuset" Cpu Name = "cpu" Cpuacct Name = "cpuacct" Memory Name = "memory" Blkio Name = "blkio" Rdma Name = "rdma" )
Subsystems returns a complete list of the default cgroups available on most linux systems
NestedPath will nest the cgroups based on the calling processes cgroup placing its child processes inside its own path
PidPath will return the correct cgroup paths for an existing process running inside a cgroup This is commonly used for the Load function to restore an existing container
StaticPath returns a static path to use for all cgroups
type PerfEventController struct {
// contains filtered or unexported fields
}
func NewPerfEvent(root string) *PerfEventController
func (p *PerfEventController) Name() Name
func (p *PerfEventController) Path(path string) string
type Process struct { // Subsystem is the name of the subsystem that the process is in Subsystem Name // Pid is the process id of the process Pid int // Path is the full path of the subsystem and location that the process is in Path string }
State is a type that represents the state of the current cgroup
const ( Unknown State = "" Thawed State = "thawed" Frozen State = "frozen" Freezing State = "freezing" Deleted State = "deleted" )
V1 returns all the groups in the default cgroups mountpoint in a single hierarchy
type SystemdController struct {
// contains filtered or unexported fields
}
func NewSystemd(root string) (*SystemdController, error)
func (s *SystemdController) Create(path string, resources *specs.LinuxResources) error
func (s *SystemdController) Delete(path string) error
func (s *SystemdController) Name() Name
type Task struct { // Subsystem is the name of the subsystem that the task is in Subsystem Name // Pid is the process id of the task Pid int // Path is the full path of the subsystem and location that the task is in Path string }
Path | Synopsis |
---|---|
stats/v1 | |
v2 | Devicefilter containes eBPF device filter program |
v2/stats |
Package cgroups imports 21 packages (graph) and is imported by 261 packages. Updated 2019-12-06. Refresh now. Tools for package owners.