common

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 17 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"
	CgroupSubsysIO     = "io"
	// 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"
)
View Source
const (
	IOCostCtrlModeAuto IOCostCtrlMode = "auto"
	IOCostCtrlModeUser IOCostCtrlMode = "user"
	IOCostModelLinear  IOCostModel    = "linear"
)

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 absolute cgroup path for container level

func GetContainerRelativeCgroupPath added in v0.3.0

func GetContainerRelativeCgroupPath(podUID, containerId string) (string, error)

GetContainerRelativeCgroupPath returns relative cgroup path for container level

func GetKubernetesAbsCgroupPath

func GetKubernetesAbsCgroupPath(subsys, suffix string) string

GetKubernetesAbsCgroupPath returns absolute 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 absolute cgroup path that exists for kubernetes

func GetKubernetesAnyExistRelativeCgroupPath added in v0.3.0

func GetKubernetesAnyExistRelativeCgroupPath(suffix string) (string, error)

GetKubernetesAnyExistRelativeCgroupPath returns any relative 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 absolute 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 InstrumentedWriteFileIfChange added in v0.5.4

func InstrumentedWriteFileIfChange(dir, file, data string) (err error, applied bool, oldData string)

InstrumentedWriteFileIfChange wraps WriteFileIfChange with audit 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 ParseCgroupNumaValue added in v0.4.1

func ParseCgroupNumaValue(cgroupPath, cgroupFile string) (map[string]map[int]uint64, error)

ParseCgroupNumaValue parse cgroup numa stat files like memory.numa_stat, the format is like "anon N0=1686843392 N1=1069957120 N2=316747776 N3=163962880"

func ReadTasksFile

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

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 IOCostCtrlMode added in v0.4.0

type IOCostCtrlMode string

type IOCostModel added in v0.4.0

type IOCostModel string

type IOCostModelData added in v0.4.0

type IOCostModelData struct {
	CtrlMode      IOCostCtrlMode `json:"ctrl_mode"`       //"auto" or "user"
	Model         IOCostModel    `json:"model"`           // The cost model in use - "linear"
	ReadBPS       uint64         `json:"read_bps"`        // read bytes per second
	ReadSeqIOPS   uint64         `json:"read_seq_iops"`   // sequential read IOPS
	ReadRandIOPS  uint64         `json:"read_rand_iops"`  // random read IOPS
	WriteBPS      uint64         `json:"write_bps"`       // wirte bytes per second
	WriteSeqIOPS  uint64         `json:"write_seq_iops"`  // sequential write IOPS
	WriteRandIOPS uint64         `json:"write_rand_iops"` // random write IOPS
}

IOCostModelData is the io.cost.model data supported in cgroupv2

func (*IOCostModelData) String added in v0.4.0

func (iocmd *IOCostModelData) String() string

type IOCostQoSData added in v0.4.0

type IOCostQoSData struct {
	Enable              uint32         `json:"enable"`                // Weight-based control enable
	CtrlMode            IOCostCtrlMode `json:"ctrl_mode"`             //"auto" or "user"
	ReadLatencyPercent  float32        `json:"read_latency_percent"`  // read latency percentile [0, 100]
	ReadLatencyUS       uint32         `json:"read_latency_us"`       // read latency threshold, unit microsecond
	WriteLatencyPercent float32        `json:"write_latency_percent"` // write latency percentile [0, 100]
	WriteLatencyUS      uint32         `json:"write_latency_us"`      // write latency threshold, unit microsecond
	VrateMin            float32        `json:"vrate_min"`             // vrate minimum scaling percentage [1, 10000]
	VrateMax            float32        `json:"vrate_max"`             // vrate maximum scaling percentage [1, 10000]
}

IOCostQoSData is the io.cost.qos data supported in cgroupv2

func (*IOCostQoSData) String added in v0.4.0

func (iocqd *IOCostQoSData) String() string

type MemoryData

type MemoryData struct {
	LimitInBytes       int64
	TCPMemLimitInBytes int64
	// SoftLimitInBytes for memory.low
	// Best effort memory protection, cgroup memory that will not be reclaimed in soft_limit_reclaim phase of kswapd.
	SoftLimitInBytes int64
	// MinInBytes for memory.min
	// cgroup memory that can never be reclaimed by kswapd.
	MinInBytes int64
	WmarkRatio int32
	// SwapMaxInBytes < 0 means disable cgroup-level swap
	SwapMaxInBytes int64
}

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 MemoryNumaMetrics added in v0.4.1

type MemoryNumaMetrics struct {
	Anon uint64
	File uint64
}

MemoryNumaMetrics get per-numa level 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