common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 14 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// CgroupFSMountPoint default cgroup mount point
	CgroupFSMountPoint = "/sys/fs/cgroup"
	// DefaultSelectedSubsys cgroupv1 default select subsys
	DefaultSelectedSubsys = "cpu"
	// CgroupTasksFileV1 thread id file for cgroupv1
	CgroupTasksFileV1 = "tasks"
	// CgroupTasksFileV2 thread id file for cgroupv2
	CgroupTasksFileV2 = "cgroup.threads"

	CgroupSubsysCPUSet = "cpuset"
	CgroupSubsysMemory = "memory"
	CgroupSubsysCPU    = "cpu"
	// CgroupSubsysNetCls is the net_cls sub-system
	CgroupSubsysNetCls = "net_cls"

	PodCgroupPathPrefix        = "pod"
	CgroupFsRootPath           = "/kubepods"
	CgroupFsRootPathBestEffort = "/kubepods/besteffort"
	CgroupFsRootPathBurstable  = "/kubepods/burstable"

	SystemdRootPath           = "/kubepods.slice"
	SystemdRootPathBestEffort = "/kubepods.slice/kubepods-besteffort.slice"
	SystemdRootPathBurstable  = "/kubepods.slice/kubepods-burstable.slice"
)
View Source
const (
	CgroupTypeCgroupfs = "cgroupfs"
	CgroupTypeSystemd  = "systemd"
)

Variables

This section is empty.

Functions

func CheckCgroup2UnifiedMode added in v0.2.0

func CheckCgroup2UnifiedMode() bool

CheckCgroup2UnifiedMode return whether it is in cgroupv2 env

func GetAbsCgroupPath

func GetAbsCgroupPath(subsys, suffix string) string

GetAbsCgroupPath get absolute cgroup path for relative cgroup path

func GetCgroupParamInt

func GetCgroupParamInt(cgroupPath, cgroupFile string) (int64, error)

func GetCgroupRootPath

func GetCgroupRootPath(subsys string) string

GetCgroupRootPath get cgroupfs root path compatible with v1 and v2

func GetContainerAbsCgroupPath

func GetContainerAbsCgroupPath(subsys, podUID, containerId string) (string, error)

GetContainerAbsCgroupPath returns cgroup path for container level

func GetKubernetesAbsCgroupPath

func GetKubernetesAbsCgroupPath(subsys, suffix string) string

GetKubernetesAbsCgroupPath returns cgroup path for kubernetes with the given suffix without considering whether the path exists or not.

func GetKubernetesAnyExistAbsCgroupPath

func GetKubernetesAnyExistAbsCgroupPath(subsys, suffix string) (string, error)

GetKubernetesAnyExistAbsCgroupPath returns any cgroup path that exists for kubernetes

func GetKubernetesCgroupRootPathWithSubSys

func GetKubernetesCgroupRootPathWithSubSys(subsys string) []string

GetKubernetesCgroupRootPathWithSubSys returns all Cgroup paths to run container for kubernetes, and the returned values are merged with subsys.

func GetPodAbsCgroupPath

func GetPodAbsCgroupPath(subsys, podUID string) (string, error)

GetPodAbsCgroupPath returns cgroup path for pod level

func InitKubernetesCGroupPath

func InitKubernetesCGroupPath(cgroupType CgroupType, additionalK8SCGroupPath []string)

InitKubernetesCGroupPath can only be called once to init dynamic cgroup path configurations. additionalCGroupPath is set because we may have legacy cgroup path settings, so it will be used as an adaptive logic.

func IsCPUIdleSupported added in v0.2.0

func IsCPUIdleSupported() bool

IsCPUIdleSupported checks if cpu idle supported by checking if the cpu.idle interface file exists

func IsContainerCgroupExist added in v0.2.0

func IsContainerCgroupExist(podUID, containerID string) (bool, error)

func ReadTasksFile

func ReadTasksFile(file string) ([]string, error)

func WriteFileIfChange

func WriteFileIfChange(dir, file, data string) (error, bool, string)

WriteFileIfChange writes data to the cgroup joined by dir and file if new data is not equal to the old data and return the old data.

Types

type CPUData

type CPUData struct {
	Shares     uint64
	CpuPeriod  uint64
	CpuQuota   int64
	CpuIdlePtr *bool
}

CPUData set cgroup cpu data

type CPUMetrics

type CPUMetrics struct {
	UsageTotal  uint64
	UsageKernel uint64
	UsageUser   uint64
}

CPUMetrics get cpu cgroup metrics

type CPUSetData

type CPUSetData struct {
	CPUs    string
	Mems    string
	Migrate string
}

CPUSetData set cgroup cpuset data

type CPUSetStats

type CPUSetStats struct {
	CPUs string
	Mems string
}

CPUSetStats get cgroup cpuset data

type CPUStats

type CPUStats struct {
	CpuPeriod uint64
	CpuQuota  int64
}

CPUStats get cgroup cpu data

type CgroupMetrics

type CgroupMetrics struct {
	CPU    *CPUMetrics
	Memory *MemoryMetrics
	Pid    *PidMetrics
}

CgroupMetrics cgroup metrics

type CgroupType

type CgroupType string

CgroupType defines the cgroup type that kubernetes version uses, and CgroupTypeCgroupfs will used as the default one.

type MemoryData

type MemoryData struct {
	LimitInBytes int64
	WmarkRatio   int32
}

MemoryData set cgroup memory data

type MemoryMetrics

type MemoryMetrics struct {
	RSS         uint64
	Cache       uint64
	Dirty       uint64
	WriteBack   uint64
	UsageUsage  uint64
	KernelUsage uint64
	// memory.memsw.usage_in_bytes Reports the total size in
	// bytes of the memory and swap space used by tasks in the cgroup.
	MemSWUsage uint64
}

MemoryMetrics get memory cgroup metrics

type MemoryStats

type MemoryStats struct {
	Limit uint64
	Usage uint64
}

MemoryStats get cgroup memory data

type NetClsData

type NetClsData struct {
	// ClassID is the class id of the container.
	ClassID uint32
	// CgroupID is used for cgroup v2.
	CgroupID uint64
	// Attributes are some optional attributes.
	Attributes map[string]string
}

NetClsData is the net class data.

type PidMetrics

type PidMetrics struct {
	Current uint64
	Limit   uint64
}

PidMetrics get pid cgroup metrics

Jump to

Keyboard shortcuts

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