cgroups

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Generic unset value that means undefined or not set
	CGROUP_UNSET_VALUE = 0

	// Max cgroup subsystems count that is used from BPF side
	// to define a max index for the default controllers on tasks.
	// For further documentation check BPF part.
	CGROUP_SUBSYS_COUNT = 15

	// The default hierarchy for cgroupv2
	CGROUP_DEFAULT_HIERARCHY = 0
)

Variables

View Source
var (

	/* Cgroup controllers that we are interested in
	 * are usually the ones that are setup by systemd
	 * or other init programs.
	 */
	CgroupControllers = []CgroupController{
		{Name: "memory"},
		{Name: "pids"},
		{Name: "cpuset"},
	}
)

Functions

func CgroupFsMagicStr

func CgroupFsMagicStr(magic uint64) string

DetectCgroupFSMagic() runs by default DetectCgroupMode() CgroupFsMagicStr() Returns "Cgroupv2" or "Cgroupv1" based on passed magic.

func CgroupIDFromPID added in v1.3.2

func CgroupIDFromPID(pid uint32) (uint64, error)

CgroupIDFromPID returns the cgroup id for a given pid.

func CgroupNameFromCStr

func CgroupNameFromCStr(cstr []byte) string

CgroupNameFromCstr() Returns a Golang string from the passed C language format string.

func DetectCgroupFSMagic

func DetectCgroupFSMagic() (uint64, error)

DetectCgroupFSMagic() runs by default DetectCgroupMode() Return the Cgroupfs v1 or v2 that will be used by bpf programs

func DetectDeploymentMode

func DetectDeploymentMode() (uint32, error)

func DiscoverSubSysIds

func DiscoverSubSysIds() error

DiscoverSubSysIds() Discover Cgroup SubSys IDs and indexes. of the corresponding controllers that we are interested in. We need this dynamic behavior since these controllers are compile config.

func GetCgroupFSMagic

func GetCgroupFSMagic() uint64

func GetCgroupFSPath

func GetCgroupFSPath() string

func GetCgroupIDFromSubCgroup added in v1.3.2

func GetCgroupIDFromSubCgroup(p string) (uint64, error)

GetCgroupIDFromSubCgroup deals with some idiosyncrancies of container runtimes

Typically, the container processes run in the cgroup path specified in the OCI spec under cgroupsPath. crun, however, is an exception because it uses another directory (called subgroup) under the cgroupsPath: https://github.com/containers/crun/blob/main/crun.1.md#runocisystemdsubgroupsubgroup.

This function deals with this by checking for a child directory. If it finds one (and only one) it uses the cgroup id from the child.

func GetCgroupIdFromPath

func GetCgroupIdFromPath(cgroupPath string) (uint64, error)

func GetCgrpControllerName

func GetCgrpControllerName() string

GetCgrpControllerName() returns the name of the controller that is being used as fallback from the css to get cgroup information and track processes.

func GetCgrpHierarchyID

func GetCgrpHierarchyID() uint32

GetCgrpHierarchyID() returns the ID of the Cgroup hierarchy that is used to track processes. This is used mostly for Cgroupv1 as for Cgroupv2 we run in the default hierarchy.

func GetCgrpv1SubsystemIdx added in v1.3.2

func GetCgrpv1SubsystemIdx() uint32

GetCgrpSubsystemIdx() returns the Index of the subsys or hierarchy to be used to track processes.

func HostCgroupRoot added in v0.8.20

func HostCgroupRoot() (string, error)

HostCgroupRoot tries to retrieve the host cgroup root

For cgroupv1, we return the directory of the contoller currently used.

NB(kkourt): for now we are checking /sys/fs/cgroup under host /proc's init. For systems where the cgroup is mounted in a non-standard location, we could also check host's /proc/mounts.

Types

type CgroupController

type CgroupController struct {
	Id     uint32 // Hierarchy unique ID
	Idx    uint32 // Cgroup SubSys index
	Name   string // Controller name
	Active bool   // Will be set to true if controller is set and active
}

type CgroupModeCode

type CgroupModeCode int
const (
	/* Cgroup Mode:
	 * https://systemd.io/CGROUP_DELEGATION/
	 * But this should work also for non-systemd environments: where
	 * only legacy or unified are available by default.
	 */
	CGROUP_UNDEF   CgroupModeCode = iota
	CGROUP_LEGACY  CgroupModeCode = 1
	CGROUP_HYBRID  CgroupModeCode = 2
	CGROUP_UNIFIED CgroupModeCode = 3
)

func DetectCgroupMode

func DetectCgroupMode() (CgroupModeCode, error)

DetectCgroupMode() Returns the current Cgroup mode that is applied to the system This applies to systemd and non-systemd machines, possible values:

  • CGROUP_UNDEF: undefined
  • CGROUP_LEGACY: Cgroupv1 legacy controllers
  • CGROUP_HYBRID: Cgroupv1 and Cgroupv2 set up by systemd
  • CGROUP_UNIFIED: Pure Cgroupv2 hierarchy

Reference: https://systemd.io/CGROUP_DELEGATION/

func GetCgroupMode

func GetCgroupMode() CgroupModeCode

func (CgroupModeCode) String

func (code CgroupModeCode) String() string

type DeploymentCode

type DeploymentCode int
const (
	// Deployment modes
	DEPLOY_UNKNOWN    DeploymentCode = iota
	DEPLOY_K8S        DeploymentCode = 1  // K8s deployment
	DEPLOY_CONTAINER  DeploymentCode = 2  // Container docker, podman, etc
	DEPLOY_SD_SERVICE DeploymentCode = 10 // Systemd service
	DEPLOY_SD_USER    DeploymentCode = 11 // Systemd user session
)

func GetDeploymentMode

func GetDeploymentMode() DeploymentCode

func (DeploymentCode) String

func (op DeploymentCode) String() string

type FileHandle

type FileHandle struct {
	Id uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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