system

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: Apache-2.0 Imports: 29 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultCPUCFSPeriod    int64 = 100000
	CPUShareKubeBEValue    int64 = 2
	CPUShareUnitValue      int64 = 1024
	CFSQuotaUnlimitedValue int64 = -1
	// MemoryLimitUnlimitedValue denotes the unlimited value of cgroups-v1 memory.limit_in_bytes.
	// It derives from linux PAGE_COUNTER_MAX and may be different according to the PAGE_SIZE (here we suppose `4k`).
	// https://github.com/torvalds/linux/blob/ea4424be16887a37735d6550cfd0611528dbe5d9/mm/memcontrol.c#L5337
	MemoryLimitUnlimitedValue int64 = 0x7FFFFFFFFFFFF000 // 9223372036854771712 < math.MaxInt64

	// CgroupMaxSymbolStr only appears in cgroups-v2 files, we consider the value as MaxInt64
	CgroupMaxSymbolStr string = "max"
	// CgroupMaxValueStr math.MaxInt64; writing `memory.high` with this do the same as set as "max"
	CgroupMaxValueStr string = "9223372036854775807"
)
View Source
const (
	CgroupControllersName    = "cgroup.controllers"
	CgroupSubtreeControlName = "cgroup.subtree_control"
)
View Source
const (
	Cgroupfs CgroupDriverType = "cgroupfs"
	Systemd  CgroupDriverType = "systemd"

	KubeRootNameSystemd       = "kubepods.slice/"
	KubeBurstableNameSystemd  = "kubepods-burstable.slice/"
	KubeBesteffortNameSystemd = "kubepods-besteffort.slice/"

	KubeRootNameCgroupfs       = "kubepods/"
	KubeBurstableNameCgroupfs  = "burstable/"
	KubeBesteffortNameCgroupfs = "besteffort/"
)
View Source
const (
	CgroupCPUDir     string = "cpu/"
	CgroupCPUSetDir  string = "cpuset/"
	CgroupCPUAcctDir string = "cpuacct/"
	CgroupMemDir     string = "memory/"
	CgroupBlkioDir   string = "blkio/"

	CgroupV2Dir = ""
)
View Source
const (
	CFSBasePeriodValue int64 = 100000
	CFSQuotaMinValue   int64 = 1000 // min value except `-1`
	CPUSharesMinValue  int64 = 2
	CPUWeightMinValue  int64 = 1
	CPUWeightMaxValue  int64 = 10000

	CPUStatName      = "cpu.stat"
	CPUSharesName    = "cpu.shares"
	CPUCFSQuotaName  = "cpu.cfs_quota_us"
	CPUCFSPeriodName = "cpu.cfs_period_us"
	CPUBVTWarpNsName = "cpu.bvt_warp_ns"
	CPUBurstName     = "cpu.cfs_burst_us"
	CPUTasksName     = "tasks"
	CPUProcsName     = "cgroup.procs"
	CPUThreadsName   = "cgroup.threads"
	CPUMaxName       = "cpu.max"
	CPUWeightName    = "cpu.weight"

	CPUSetCPUSName          = "cpuset.cpus"
	CPUSetCPUSEffectiveName = "cpuset.cpus.effective"

	CPUAcctStatName           = "cpuacct.stat"
	CPUAcctUsageName          = "cpuacct.usage"
	CPUAcctCPUPressureName    = "cpu.pressure"
	CPUAcctMemoryPressureName = "memory.pressure"
	CPUAcctIOPressureName     = "io.pressure"

	MemoryLimitName            = "memory.limit_in_bytes"
	MemoryUsageName            = "memory.usage_in_bytes"
	MemoryStatName             = "memory.stat"
	MemoryWmarkRatioName       = "memory.wmark_ratio"
	MemoryWmarkScaleFactorName = "memory.wmark_scale_factor"
	MemoryWmarkMinAdjName      = "memory.wmark_min_adj"
	MemoryMinName              = "memory.min"  // anolis os or cgroups-v2
	MemoryLowName              = "memory.low"  // anolis os or cgroups-v2
	MemoryHighName             = "memory.high" // anolis os or cgroups-v2
	MemoryMaxName              = "memory.max"
	MemoryCurrentName          = "memory.current"
	MemoryPriorityName         = "memory.priority"
	MemoryUsePriorityOomName   = "memory.use_priority_oom"
	MemoryOomGroupName         = "memory.oom.group"

	BlkioTRIopsName = "blkio.throttle.read_iops_device"
	BlkioTRBpsName  = "blkio.throttle.read_bps_device"
	BlkioTWIopsName = "blkio.throttle.write_iops_device"
	BlkioTWBpsName  = "blkio.throttle.write_bps_device"
)
View Source
const (
	DS_MODE   = "dsMode"
	HOST_MODE = "hostMode"
)
View Source
const (
	CPUInfoFileName       string = "cpuinfo"
	KernelCmdlineFileName string = "cmdline"

	ResctrlName string = "resctrl"

	ResctrlDir string = "resctrl/"
	RdtInfoDir string = "info"
	L3CatDir   string = "L3"

	ResctrlSchemataName string = "schemata"
	ResctrlCbmMaskName  string = "cbm_mask"
	ResctrlTasksName    string = "tasks"

	// L3SchemataPrefix is the prefix of l3 cat schemata
	L3SchemataPrefix = "L3"
	// MbSchemataPrefix is the prefix of mba schemata
	MbSchemataPrefix = "MB"
)
View Source
const (
	ProcStatName    = "stat"
	ProcMemInfoName = "meminfo"
	SysctlSubDir    = "sys"

	KernelSchedGroupIdentityEnable = "kernel/sched_group_identity_enabled"
)
View Source
const EmptyValueError string = "EmptyValueError"
View Source
const ErrResourceUnsupportedPrefix = "resource is unsupported"

Variables

View Source
var (
	NaturalInt64Validator = &RangeValidator{min: 0, max: math.MaxInt64}

	CPUSharesValidator                      = &RangeValidator{min: CPUSharesMinValue, max: math.MaxInt64}
	CPUBurstValidator                       = &RangeValidator{min: 0, max: 100 * 10 * 100000}
	CPUBvtWarpNsValidator                   = &RangeValidator{min: -1, max: 2}
	CPUWeightValidator                      = &RangeValidator{min: CPUWeightMinValue, max: CPUWeightMaxValue}
	MemoryWmarkRatioValidator               = &RangeValidator{min: 0, max: 100}
	MemoryPriorityValidator                 = &RangeValidator{min: 0, max: 12}
	MemoryOomGroupValidator                 = &RangeValidator{min: 0, max: 1}
	MemoryUsePriorityOomValidator           = &RangeValidator{min: 0, max: 1}
	MemoryWmarkMinAdjValidator              = &RangeValidator{min: -25, max: 50}
	MemoryWmarkScaleFactorFileNameValidator = &RangeValidator{min: 1, max: 1000}

	CPUSetCPUSValidator = &CPUSetStrValidator{}
)
View Source
var (
	DefaultFactory = NewCgroupResourceFactory()

	CPUStat      = DefaultFactory.New(CPUStatName, CgroupCPUDir)
	CPUShares    = DefaultFactory.New(CPUSharesName, CgroupCPUDir).WithValidator(CPUSharesValidator)
	CPUCFSQuota  = DefaultFactory.New(CPUCFSQuotaName, CgroupCPUDir)
	CPUCFSPeriod = DefaultFactory.New(CPUCFSPeriodName, CgroupCPUDir)
	CPUBurst     = DefaultFactory.New(CPUBurstName, CgroupCPUDir).WithValidator(CPUBurstValidator).WithCheckSupported(SupportedIfFileExists)
	CPUBVTWarpNs = DefaultFactory.New(CPUBVTWarpNsName, CgroupCPUDir).WithValidator(CPUBvtWarpNsValidator).WithCheckSupported(SupportedIfFileExists)
	CPUTasks     = DefaultFactory.New(CPUTasksName, CgroupCPUDir)
	CPUProcs     = DefaultFactory.New(CPUProcsName, CgroupCPUDir)

	CPUSet = DefaultFactory.New(CPUSetCPUSName, CgroupCPUSetDir).WithValidator(CPUSetCPUSValidator)

	CPUAcctStat           = DefaultFactory.New(CPUAcctStatName, CgroupCPUAcctDir)
	CPUAcctUsage          = DefaultFactory.New(CPUAcctUsageName, CgroupCPUAcctDir)
	CPUAcctCPUPressure    = DefaultFactory.New(CPUAcctCPUPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExists)
	CPUAcctMemoryPressure = DefaultFactory.New(CPUAcctMemoryPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExists)
	CPUAcctIOPressure     = DefaultFactory.New(CPUAcctIOPressureName, CgroupCPUAcctDir).WithCheckSupported(SupportedIfFileExists)

	MemoryLimit            = DefaultFactory.New(MemoryLimitName, CgroupMemDir)
	MemoryUsage            = DefaultFactory.New(MemoryUsageName, CgroupMemDir)
	MemoryStat             = DefaultFactory.New(MemoryStatName, CgroupMemDir)
	MemoryWmarkRatio       = DefaultFactory.New(MemoryWmarkRatioName, CgroupMemDir).WithValidator(MemoryWmarkRatioValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryWmarkRatioName, CgroupMemDir))
	MemoryWmarkScaleFactor = DefaultFactory.New(MemoryWmarkScaleFactorName, CgroupMemDir).WithValidator(MemoryWmarkScaleFactorFileNameValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryWmarkScaleFactorName, CgroupMemDir))
	MemoryWmarkMinAdj      = DefaultFactory.New(MemoryWmarkMinAdjName, CgroupMemDir).WithValidator(MemoryWmarkMinAdjValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryWmarkMinAdjName, CgroupMemDir))
	MemoryMin              = DefaultFactory.New(MemoryMinName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithSupported(SupportedIfFileExistsInKubepods(MemoryMinName, CgroupMemDir))
	MemoryLow              = DefaultFactory.New(MemoryLowName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithSupported(SupportedIfFileExistsInKubepods(MemoryLowName, CgroupMemDir))
	MemoryHigh             = DefaultFactory.New(MemoryHighName, CgroupMemDir).WithValidator(NaturalInt64Validator).WithSupported(SupportedIfFileExistsInKubepods(MemoryHighName, CgroupMemDir))
	MemoryPriority         = DefaultFactory.New(MemoryPriorityName, CgroupMemDir).WithValidator(MemoryPriorityValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryPriorityName, CgroupMemDir))
	MemoryUsePriorityOom   = DefaultFactory.New(MemoryUsePriorityOomName, CgroupMemDir).WithValidator(MemoryUsePriorityOomValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryUsePriorityOomName, CgroupMemDir))
	MemoryOomGroup         = DefaultFactory.New(MemoryOomGroupName, CgroupMemDir).WithValidator(MemoryOomGroupValidator).WithSupported(SupportedIfFileExistsInKubepods(MemoryOomGroupName, CgroupMemDir))

	BlkioReadIops  = DefaultFactory.New(BlkioTRIopsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator)
	BlkioReadBps   = DefaultFactory.New(BlkioTRBpsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator)
	BlkioWriteIops = DefaultFactory.New(BlkioTWIopsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator)
	BlkioWriteBps  = DefaultFactory.New(BlkioTWBpsName, CgroupBlkioDir).WithValidator(NaturalInt64Validator)

	CPUCFSQuotaV2            = DefaultFactory.NewV2(CPUCFSQuotaName, CPUMaxName)
	CPUCFSPeriodV2           = DefaultFactory.NewV2(CPUCFSPeriodName, CPUMaxName)
	CPUSharesV2              = DefaultFactory.NewV2(CPUSharesName, CPUWeightName).WithValidator(CPUWeightValidator)
	CPUStatV2                = DefaultFactory.NewV2(CPUStatName, CPUStatName)
	CPUAcctStatV2            = DefaultFactory.NewV2(CPUAcctStatName, CPUStatName)
	CPUAcctUsageV2           = DefaultFactory.NewV2(CPUAcctUsageName, CPUStatName)
	CPUSetV2                 = DefaultFactory.NewV2(CPUSetCPUSName, CPUSetCPUSName).WithValidator(CPUSetCPUSValidator)
	CPUSetEffectiveV2        = DefaultFactory.NewV2(CPUSetCPUSEffectiveName, CPUSetCPUSEffectiveName) // TODO: unify the R/W
	CPUTasksV2               = DefaultFactory.NewV2(CPUTasksName, CPUThreadsName)
	CPUProcsV2               = DefaultFactory.NewV2(CPUProcsName, CPUProcsName)
	MemoryLimitV2            = DefaultFactory.NewV2(MemoryLimitName, MemoryMaxName)
	MemoryUsageV2            = DefaultFactory.NewV2(MemoryUsageName, MemoryCurrentName)
	MemoryStatV2             = DefaultFactory.NewV2(MemoryStatName, MemoryStatName)
	MemoryMinV2              = DefaultFactory.NewV2(MemoryMinName, MemoryMinName)
	MemoryLowV2              = DefaultFactory.NewV2(MemoryLowName, MemoryLowName)
	MemoryHighV2             = DefaultFactory.NewV2(MemoryHighName, MemoryHighName)
	MemoryWmarkRatioV2       = DefaultFactory.NewV2(MemoryWmarkRatioName, MemoryWmarkRatioName).WithValidator(MemoryWmarkRatioValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryWmarkScaleFactorV2 = DefaultFactory.NewV2(MemoryWmarkScaleFactorName, MemoryWmarkScaleFactorName).WithValidator(MemoryWmarkScaleFactorFileNameValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryWmarkMinAdjV2      = DefaultFactory.NewV2(MemoryWmarkMinAdjName, MemoryWmarkMinAdjName).WithValidator(MemoryWmarkMinAdjValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryPriorityV2         = DefaultFactory.NewV2(MemoryPriorityName, MemoryPriorityName).WithValidator(MemoryPriorityValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryUsePriorityOomV2   = DefaultFactory.NewV2(MemoryUsePriorityOomName, MemoryUsePriorityOomName).WithValidator(MemoryUsePriorityOomValidator).WithCheckSupported(SupportedIfFileExists)
	MemoryOomGroupV2         = DefaultFactory.NewV2(MemoryOomGroupName, MemoryOomGroupName).WithValidator(MemoryOomGroupValidator).WithCheckSupported(SupportedIfFileExists)
)

for cgroup resources, we use the corresponding cgroups-v1 filename as its resource type

View Source
var AgentMode = DS_MODE
View Source
var CgroupPathFormatter = cgroupPathFormatterInSystemd

default use Systemd cgroup path format

View Source
var (
	CommonRootDir = "" // for uni-test
)
View Source
var DefaultRegistry = NewCgroupResourceRegistry()
View Source
var ExecCmdOnHost = execCmdOnHostFn

If running in container, exec command by 'nsenter --mount=/proc/1/ns/mnt ${cmds}'. return stdout, exitcode, error

View Source
var HostSystemInfo = collectVersionInfo()
View Source
var (
	// Jiffies is the duration unit of CPU stats. Normally, it is 10ms.
	Jiffies = float64(10 * time.Millisecond)
)
View Source
var PidOf = pidOfFn

PidOf finds process(es) with a specified name (regexp match) and return their pid(s).

View Source
var UseCgroupsV2 bool

Functions

func CalcCPUThrottledRatio

func CalcCPUThrottledRatio(curPoint, prePoint *CPUStatRaw) float64

func CalculateCatL3MaskValue added in v1.1.0

func CalculateCatL3MaskValue(cbm uint, startPercent, endPercent int64) (string, error)

func CgroupFileRead

func CgroupFileRead(cgroupTaskDir string, r Resource) (string, error)

CgroupFileRead reads the cgroup file. TODO: moved into resourceexecutor package and marked as private.

func CgroupFileReadInt

func CgroupFileReadInt(cgroupTaskDir string, r Resource) (*int64, error)

CgroupFileReadInt reads the cgroup file and returns an int64 value. TODO: moved into resourceexecutor package and marked as private.

func CgroupFileWrite

func CgroupFileWrite(cgroupTaskDir string, r Resource, value string) error

CgroupFileWrite writes the cgroup file with the given value. TODO: moved into resourceexecutor package and marked as private.

func CgroupFileWriteIfDifferent

func CgroupFileWriteIfDifferent(cgroupTaskDir string, r Resource, value string) error

CgroupFileWriteIfDifferent writes the cgroup file if current value is different from the given value. TODO: moved into resourceexecutor package and marked as private.

func CheckAndTryEnableResctrlCat

func CheckAndTryEnableResctrlCat() error

CheckAndTryEnableResctrlCat checks if resctrl and l3_cat are enabled; if not, try to enable the features by mount resctrl subsystem; See MountResctrlSubsystem() for the detail. It returns whether the resctrl cat is enabled, and the error if failed to enable or to check resctrl interfaces

func CheckIfAllSupported added in v1.1.0

func CheckIfAllSupported(checkSupportedFns ...func() (bool, string)) func() (bool, string)

func CommonFileRead

func CommonFileRead(file string) (string, error)

func CommonFileWrite

func CommonFileWrite(file string, data string) error

func CommonFileWriteIfDifferent

func CommonFileWriteIfDifferent(file string, value string) error

func ConvertCPUSharesToWeight added in v1.1.0

func ConvertCPUSharesToWeight(s string) (int64, error)

func ConvertCPUWeightToShares added in v1.1.0

func ConvertCPUWeightToShares(v int64) (int64, error)

ConvertCPUWeightToShares converts the value of `cpu.weight` (cgroups-v2) into the value of `cpu.shares` (cgroups-v1)

func FileExists

func FileExists(path string) bool

func GetCacheInfo added in v1.1.0

func GetCacheInfo(str string) (string, int32, error)

GetCacheInfo parses the output of `lscpu -e=CACHE` into l1l2 and l3 infos e.g. - input: "1:1:1:0" - output: "1", 0, nil

func GetCgroupCurTasks

func GetCgroupCurTasks(cgroupPath string) ([]int, error)

func GetCgroupFilePath

func GetCgroupFilePath(cgroupTaskDir string, r Resource) string

@cgroupTaskDir kubepods.slice/kubepods-pod7712555c_ce62_454a_9e18_9ff0217b8941.slice/ @return /sys/fs/cgroup/cpu/kubepods.slice/kubepods-pod7712555c_ce62_454a_9e18_9ff0217b8941.slice/cpu.shares

func GetKubeletCommandline added in v1.1.0

func GetKubeletCommandline(port int) ([]string, error)

func GetPeriodTicks added in v1.1.0

func GetPeriodTicks(start, end time.Time) float64

func GetProcFilePath added in v1.1.0

func GetProcFilePath(file string) string

func GetProcSysFilePath added in v1.1.0

func GetProcSysFilePath(file string) string

func GetResctrlGroupRootDirPath

func GetResctrlGroupRootDirPath(groupPath string) string

@groupPath BE @return /sys/fs/resctrl/BE

func GetResctrlL3CbmFilePath

func GetResctrlL3CbmFilePath() string

@return /sys/fs/resctrl/info/L3/cbm_mask

func GetResctrlSchemataFilePath

func GetResctrlSchemataFilePath(groupPath string) string

@groupPath BE @return /sys/fs/resctrl/BE/schemata

func GetResctrlSubsystemDirPath

func GetResctrlSubsystemDirPath() string

@return /sys/fs/resctrl

func GetResctrlTasksFilePath

func GetResctrlTasksFilePath(groupPath string) string

@groupPath BE @return /sys/fs/resctrl/BE/tasks

func InitCatGroupIfNotExist added in v1.1.0

func InitCatGroupIfNotExist(group string) error

func IsResourceUnsupportedErr added in v1.1.0

func IsResourceUnsupportedErr(err error) bool

func IsSupportResctrl added in v1.1.0

func IsSupportResctrl() (bool, error)

func IsUsingCgroupsV2 added in v1.1.0

func IsUsingCgroupsV2() bool

func KubeletPortToPid added in v1.1.0

func KubeletPortToPid(port int) (int, error)

KubeletPortToPid Query pid by tcp port number with the help of go-netstat note: Due to the low efficiency of full traversal, we cache the result and verify each time

func MountResctrlSubsystem

func MountResctrlSubsystem() (bool, error)

MountResctrlSubsystem mounts resctrl fs under the sysFSRoot to enable the kernel feature on supported environment NOTE: Linux kernel (>= 4.10), Intel cpu and bare-mental host are required; Also, Intel RDT features should be enabled in kernel configurations and kernel commandline. For more info, please see https://github.com/intel/intel-cmt-cat/wiki/resctrl

func NewProcSysctl added in v1.1.0

func NewProcSysctl() utilsysctl.Interface

func ParseCPUAcctUsageV2 added in v1.1.0

func ParseCPUAcctUsageV2(content string) (uint64, error)

func ParseCPUCFSPeriodV2 added in v1.1.0

func ParseCPUCFSPeriodV2(content string) (int64, error)

func ParseCPUCFSQuotaV2 added in v1.1.0

func ParseCPUCFSQuotaV2(content string) (int64, error)

func ParseKVMap added in v1.1.0

func ParseKVMap(content string) map[string]string

ParseKVMap parses a file content into a KV map. e.g. `user 100\nsystem 20` -> `{"user": "100", "system": "20"}`

func ParseResctrlSchemataMap added in v1.1.0

func ParseResctrlSchemataMap(content string) map[string]map[int]string

ParseResctrlSchemataMap parses the content of resctrl schemata. e.g. schemata=`L3:0=fff;1=fff\nMB:0=100;1=100\n` -> `{"L3": {0: "fff", 1: "fff"}, "MB": {0: "100", 1: "100"}}`

func PathExists

func PathExists(path string) (bool, error)

func ProcCmdLine

func ProcCmdLine(procRoot string, pid int) ([]string, error)

CmdLine returns the command line args of a process.

func ReadCatL3CbmString

func ReadCatL3CbmString() (string, error)

ReadCatL3CbmString reads and returns the value of cat l3 cbm_mask

func ReadCgroupAndParseInt32Slice added in v1.1.0

func ReadCgroupAndParseInt32Slice(parentDir string, r Resource) ([]int32, error)

ReadCgroupAndParseInt32Slice reads the given cgroup content and parses it into an int32 slice. e.g. content: "1\n23\n0\n4\n56789" -> []int32{ 1, 23, 0, 4, 56789 }

func ReadCgroupAndParseInt64 added in v1.1.0

func ReadCgroupAndParseInt64(parentDir string, r Resource) (int64, error)

func ReadCgroupAndParseUint64 added in v1.1.0

func ReadCgroupAndParseUint64(parentDir string, r Resource) (uint64, error)

func ReadFileNoStat

func ReadFileNoStat(filename string) ([]byte, error)

ReadFileNoStat uses io.ReadAll to read contents of entire file. This is similar to io.ReadFile but without the call to os.Stat, because many files in /proc and /sys report incorrect file sizes (either 0 or 4096). Reads a max file size of 512kB. For files larger than this, a scanner should be used.

func ReadResctrlTasksMap

func ReadResctrlTasksMap(groupPath string) (map[int32]struct{}, error)

ReadResctrlTasksMap reads and returns the map of given resctrl group's task ids

func ResourceUnsupportedErr added in v1.1.0

func ResourceUnsupportedErr(msg string) error

func SetConf

func SetConf(config Config)

func SetSchedGroupIdentity added in v1.1.0

func SetSchedGroupIdentity(enable bool) error

func SetupCgroupPathFormatter

func SetupCgroupPathFormatter(driver CgroupDriverType)

func SupportedIfFileExists added in v1.1.0

func SupportedIfFileExists(r Resource, parentDir string) (bool, string)

func SupportedIfFileExistsInKubepods added in v1.1.0

func SupportedIfFileExistsInKubepods(filename string, subfs string) (bool, string)

func TCPSocks added in v1.1.0

func TCPSocks(fn netstat.AcceptFn) ([]netstat.SockTabEntry, error)

func ValidateResourceValue added in v1.1.0

func ValidateResourceValue(value *int64, parentDir string, r Resource) bool

func WorkingDirOf added in v1.1.0

func WorkingDirOf(pid int) (string, error)

return working dir of process

Types

type CPUSetStrValidator added in v1.1.0

type CPUSetStrValidator struct{}

func (*CPUSetStrValidator) Validate added in v1.1.0

func (c *CPUSetStrValidator) Validate(value string) (bool, string)

type CPUStatRaw

type CPUStatRaw struct {
	NrPeriods            int64
	NrThrottled          int64
	ThrottledNanoSeconds int64
}

func ParseCPUStatRaw added in v1.1.0

func ParseCPUStatRaw(content string) (*CPUStatRaw, error)

func ParseCPUStatRawV2 added in v1.1.0

func ParseCPUStatRawV2(content string) (*CPUStatRaw, error)

func ReadCPUStatRaw added in v1.1.0

func ReadCPUStatRaw(cgroupPath string) (*CPUStatRaw, error)

ReadCPUStatRaw reads the cpu.stat under the given cgroup path. DEPRECATED: use NewCgroupReader().ReadCPUStat() instead.

type CPUStatV2Raw added in v1.1.0

type CPUStatV2Raw struct {
	UsageUsec  int64
	UserUsec   int64
	SystemUSec int64

	NrPeriods     int64
	NrThrottled   int64
	ThrottledUSec int64
}

func ParseCPUAcctStatRawV2 added in v1.1.0

func ParseCPUAcctStatRawV2(content string) (*CPUStatV2Raw, error)

type CgroupDriverType

type CgroupDriverType string

func GuessCgroupDriverFromCgroupName

func GuessCgroupDriverFromCgroupName() CgroupDriverType

func GuessCgroupDriverFromKubeletPort added in v1.1.0

func GuessCgroupDriverFromKubeletPort(port int) (CgroupDriverType, error)

Guess Kubelet's cgroup driver from kubelet port.

  1. use KubeletPortToPid to get kubelet pid.
  2. If '--cgroup-driver' in args, that's it. else if '--config' not in args, is default driver('cgroupfs'). else go to step-3.
  3. If kubelet config is relative path, join with /proc/${pidof kubelet}/cwd. search 'cgroupDriver:' in kubelet config file, that's it.

func (CgroupDriverType) Validate

func (c CgroupDriverType) Validate() bool

type CgroupResource added in v1.1.0

type CgroupResource struct {
	Type           ResourceType
	FileName       string
	Subfs          string
	Supported      *bool
	SupportMsg     string
	CheckSupported func(r Resource, parentDir string) (isSupported bool, msg string)
	Validator      ResourceValidator
}

func (*CgroupResource) IsSupported added in v1.1.0

func (c *CgroupResource) IsSupported(parentDir string) (bool, string)

func (*CgroupResource) IsValid added in v1.1.0

func (c *CgroupResource) IsValid(v string) (bool, string)

func (*CgroupResource) Path added in v1.1.0

func (c *CgroupResource) Path(parentDir string) string

func (*CgroupResource) ResourceType added in v1.1.0

func (c *CgroupResource) ResourceType() ResourceType

func (*CgroupResource) WithCheckSupported added in v1.1.0

func (c *CgroupResource) WithCheckSupported(checkSupportedFn func(r Resource, parentDir string) (isSupported bool, msg string)) Resource

func (*CgroupResource) WithSupported added in v1.1.0

func (c *CgroupResource) WithSupported(isSupported bool, msg string) Resource

func (*CgroupResource) WithValidator added in v1.1.0

func (c *CgroupResource) WithValidator(validator ResourceValidator) Resource

type CgroupResourceFactory added in v1.1.0

type CgroupResourceFactory interface {
	New(filename string, subfs string) Resource // cgroup-v1 filename represents the resource type
	NewV2(t ResourceType, filename string) Resource
}

func NewCgroupResourceFactory added in v1.1.0

func NewCgroupResourceFactory() CgroupResourceFactory

type CgroupResourceRegistry added in v1.1.0

type CgroupResourceRegistry interface {
	Add(v CgroupVersion, s ...Resource)
	Get(v CgroupVersion, t ResourceType) (Resource, bool)
}

func NewCgroupResourceRegistry added in v1.1.0

func NewCgroupResourceRegistry() CgroupResourceRegistry

type CgroupResourceRegistryImpl added in v1.1.0

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

func (*CgroupResourceRegistryImpl) Add added in v1.1.0

func (*CgroupResourceRegistryImpl) Get added in v1.1.0

type CgroupVersion added in v1.1.0

type CgroupVersion int32
const (
	CgroupVersionV1 CgroupVersion = 1
	CgroupVersionV2 CgroupVersion = 2
)

func GetCurrentCgroupVersion added in v1.1.0

func GetCurrentCgroupVersion() CgroupVersion

type Config

type Config struct {
	CgroupRootDir         string
	CgroupKubePath        string
	SysRootDir            string
	SysFSRootDir          string
	ProcRootDir           string
	VarRunRootDir         string
	NodeNameOverride      string
	RuntimeHooksConfigDir string

	ContainerdEndPoint string
	DockerEndPoint     string
}

func NewDsModeConfig

func NewDsModeConfig() *Config

func NewHostModeConfig

func NewHostModeConfig() *Config

func (*Config) InitFlags

func (c *Config) InitFlags(fs *flag.FlagSet)

type FileTestUtil

type FileTestUtil struct {
	// Temporary directory to store mock cgroup filesystem.
	TempDir string
	// contains filtered or unexported fields
}

func NewFileTestUtil

func NewFileTestUtil(t *testing.T) *FileTestUtil

NewFileTestUtil creates a new test util for the specified subsystem. NOTE: this function should be called only for testing purposes.

func (*FileTestUtil) Cleanup

func (c *FileTestUtil) Cleanup()

func (*FileTestUtil) CreateCgroupFile

func (c *FileTestUtil) CreateCgroupFile(taskDir string, r Resource)

func (*FileTestUtil) CreateFile

func (c *FileTestUtil) CreateFile(fileRelativePath string)

func (*FileTestUtil) CreateProcSubFile

func (c *FileTestUtil) CreateProcSubFile(fileRelativePath string)

func (*FileTestUtil) MkDirAll

func (c *FileTestUtil) MkDirAll(dirRelativePath string)

func (*FileTestUtil) ReadCgroupFileContents

func (c *FileTestUtil) ReadCgroupFileContents(taskDir string, r Resource) string

func (*FileTestUtil) ReadFileContents

func (c *FileTestUtil) ReadFileContents(fileRelativePath string) string

func (*FileTestUtil) ReadProcSubFileContents

func (c *FileTestUtil) ReadProcSubFileContents(relativeFilePath string) string

func (*FileTestUtil) SetAnolisOSResourcesSupported added in v1.1.0

func (c *FileTestUtil) SetAnolisOSResourcesSupported(supported bool)

func (*FileTestUtil) SetCgroupsV2 added in v1.1.0

func (c *FileTestUtil) SetCgroupsV2(useCgroupsV2 bool)

func (*FileTestUtil) SetResourcesSupported added in v1.1.0

func (c *FileTestUtil) SetResourcesSupported(supported bool, resources ...Resource)

func (*FileTestUtil) WriteCgroupFileContents

func (c *FileTestUtil) WriteCgroupFileContents(taskDir string, r Resource, contents string)

func (*FileTestUtil) WriteFileContents

func (c *FileTestUtil) WriteFileContents(fileRelativePath, contents string)

func (*FileTestUtil) WriteProcSubFileContents

func (c *FileTestUtil) WriteProcSubFileContents(relativeFilePath string, contents string)

type MemoryStatRaw added in v1.1.0

type MemoryStatRaw struct {
	Cache        int64
	RSS          int64
	InactiveFile int64
	ActiveFile   int64
	InactiveAnon int64
	ActiveAnon   int64
	Unevictable  int64
}

func ParseMemoryStatRaw added in v1.1.0

func ParseMemoryStatRaw(content string) (*MemoryStatRaw, error)

func ParseMemoryStatRawV2 added in v1.1.0

func ParseMemoryStatRawV2(content string) (*MemoryStatRaw, error)

func (*MemoryStatRaw) Usage added in v1.1.0

func (m *MemoryStatRaw) Usage() int64

type PSILine added in v1.1.0

type PSILine struct {
	Avg10  float64
	Avg60  float64
	Avg300 float64
	Total  uint64
}

type PSIStats added in v1.1.0

type PSIStats struct {
	Some *PSILine
	Full *PSILine

	FullSupported bool
}

func ReadPSI added in v1.1.0

func ReadPSI(pressureFilePath string) (PSIStats, error)

type ProcSysctl added in v1.1.0

type ProcSysctl struct{}

ProcSysctl implements Interface by reading and writing files under /proc/sys

func (*ProcSysctl) GetSysctl added in v1.1.0

func (*ProcSysctl) GetSysctl(sysctl string) (int, error)

func (*ProcSysctl) SetSysctl added in v1.1.0

func (*ProcSysctl) SetSysctl(sysctl string, newVal int) error

SetSysctl modifies the specified sysctl flag to the new value

type RangeValidator

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

func (*RangeValidator) Validate

func (r *RangeValidator) Validate(value string) (bool, string)

type ResctrlResource added in v1.1.0

type ResctrlResource struct {
	Type           ResourceType
	FileName       string
	Subdir         string
	CheckSupported func(r Resource, parentDir string) (isSupported bool, msg string)
	Validator      ResourceValidator
}

func (*ResctrlResource) IsSupported added in v1.1.0

func (r *ResctrlResource) IsSupported(parentDir string) (bool, string)

func (*ResctrlResource) IsValid added in v1.1.0

func (r *ResctrlResource) IsValid(v string) (bool, string)

func (*ResctrlResource) Path added in v1.1.0

func (r *ResctrlResource) Path(parentDir string) string

func (*ResctrlResource) ResourceType added in v1.1.0

func (r *ResctrlResource) ResourceType() ResourceType

func (*ResctrlResource) WithCheckSupported added in v1.1.0

func (r *ResctrlResource) WithCheckSupported(checkSupportedFn func(r Resource, parentDir string) (isSupported bool, msg string)) Resource

func (*ResctrlResource) WithSupported added in v1.1.0

func (r *ResctrlResource) WithSupported(isSupported bool, msg string) Resource

func (*ResctrlResource) WithValidator added in v1.1.0

func (r *ResctrlResource) WithValidator(validator ResourceValidator) Resource

type ResctrlSchemataRaw added in v1.1.0

type ResctrlSchemataRaw struct {
	L3    []int64
	MB    []int64
	L3Num int
}

func NewResctrlSchemataRaw added in v1.1.0

func NewResctrlSchemataRaw() *ResctrlSchemataRaw

func ReadResctrlSchemataRaw added in v1.1.0

func ReadResctrlSchemataRaw(schemataFile string, l3Num int) (*ResctrlSchemataRaw, error)

func (*ResctrlSchemataRaw) DeepCopy added in v1.1.0

func (r *ResctrlSchemataRaw) DeepCopy() *ResctrlSchemataRaw

func (*ResctrlSchemataRaw) Equal added in v1.1.0

func (*ResctrlSchemataRaw) L3Number added in v1.1.0

func (r *ResctrlSchemataRaw) L3Number() int

func (*ResctrlSchemataRaw) L3String added in v1.1.0

func (r *ResctrlSchemataRaw) L3String() string

func (*ResctrlSchemataRaw) MBString added in v1.1.0

func (r *ResctrlSchemataRaw) MBString() string

func (*ResctrlSchemataRaw) ParseResctrlSchemata added in v1.1.0

func (r *ResctrlSchemataRaw) ParseResctrlSchemata(content string, l3Num int) error

ParseResctrlSchemata parses the resctrl schemata of given cgroup, and returns the l3_cat masks and mba masks. @content `L3:0=fff;1=fff\nMB:0=100;1=100\n` (may have additional lines (e.g. ARM MPAM)) @l3Num 2 @return { L3: ["fff", "fff"], MB: ["100", "100"] }, nil

func (*ResctrlSchemataRaw) Prefix added in v1.1.0

func (r *ResctrlSchemataRaw) Prefix() string

func (*ResctrlSchemataRaw) WithL3Mask added in v1.1.0

func (r *ResctrlSchemataRaw) WithL3Mask(mask string) *ResctrlSchemataRaw

func (*ResctrlSchemataRaw) WithL3Num added in v1.1.0

func (r *ResctrlSchemataRaw) WithL3Num(l3Num int) *ResctrlSchemataRaw

func (*ResctrlSchemataRaw) WithMBPercent added in v1.1.0

func (r *ResctrlSchemataRaw) WithMBPercent(percent string) *ResctrlSchemataRaw

type Resource added in v1.1.0

type Resource interface {
	// ResourceType is the type of system resource. e.g. "cpu.cfs_quota_us", "cpu.cfs_period_us", "schemata"
	ResourceType() ResourceType
	// Path is the generated system file path according to the given parent directory.
	// e.g. "/host-cgroup/kubepods/kubepods-podxxx/cpu.shares"
	Path(parentDir string) string
	// IsSupported checks whether the system resource is supported in current platform
	IsSupported(parentDir string) (bool, string)
	// IsValid checks whether the given value is valid for the system resource's content
	IsValid(v string) (bool, string)
	// WithValidator sets the ResourceValidator for the resource
	WithValidator(validator ResourceValidator) Resource
	// WithSupported sets the Supported status of the resource when it is initialized.
	WithSupported(supported bool, msg string) Resource
	// WithCheckSupported sets the check function for the Supported status of given resource and parent directory.
	WithCheckSupported(checkSupportedFn func(r Resource, parentDir string) (isSupported bool, msg string)) Resource
}

func GetCgroupResource added in v1.1.0

func GetCgroupResource(resourceType ResourceType) (Resource, error)

func NewCommonCgroupResource added in v1.1.0

func NewCommonCgroupResource(resourceType ResourceType, filename string, subfs string) Resource

func NewCommonResctrlResource added in v1.1.0

func NewCommonResctrlResource(filename string, subdir string) Resource

type ResourceType added in v1.1.0

type ResourceType string

func GetDefaultResourceType added in v1.1.0

func GetDefaultResourceType(subfs string, filename string) ResourceType

type ResourceValidator added in v1.1.0

type ResourceValidator interface {
	Validate(value string) (isValid bool, msg string)
}

ResourceValidator validates the resource value

type SystemFile

type SystemFile struct {
	File      string
	Validator RangeValidator
}
var (
	ProcStatFile SystemFile
)

type VersionInfo

type VersionInfo struct {
	// Open Anolis OS (kernel): https://github.com/alibaba/cloud-kernel
	IsAnolisOS bool
}

Jump to

Keyboard shortcuts

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