Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertBlkIOToIOWeightValue(blkIoWeight uint16) uint64
- func ConvertCPUSharesToCgroupV2Value(cpuShares uint64) uint64
- func ConvertMemorySwapToCgroupV2Value(memorySwap, memory int64) (int64, error)
- func FindCgroupMountpoint(cgroupPath, subsystem string) (string, error)
- func FindCgroupMountpointAndRoot(cgroupPath, subsystem string) (string, string, error)
- func GetAllSubsystems() ([]string, error)
- func GetOwnCgroup(subsystem string) (string, error)
- func GetOwnCgroupPath(subsystem string) (string, error)
- func IsCgroup2UnifiedMode() bool
- func IsNotFound(err error) bool
- func NewNotFoundError(sub string) error
- func OpenFile(dir, file string, flags int) (*os.File, error)
- func ParseCgroupFile(path string) (map[string]string, error)
- func PathExists(path string) bool
- func ReadFile(dir, file string) (string, error)
- func RemovePath(path string) error
- func RemovePaths(paths map[string]string) (err error)
- func WriteCgroupProc(dir string, pid int) error
- func WriteFile(dir, file, data string) error
- type BlkioStatEntry
- type BlkioStats
- type CPUSetStats
- type CpuStats
- type CpuUsage
- type HugetlbStats
- type Manager
- type MemoryData
- type MemoryStats
- type MiscStats
- type Mount
- type NotFoundError
- type PSIData
- type PSIStats
- type PageStats
- type PageUsageByNUMA
- type PageUsageByNUMAInner
- type PidsStats
- type RdmaEntry
- type RdmaStats
- type Stats
- type ThrottlingData
Constants ¶
const (
CgroupNamePrefix = "name="
)
const (
CgroupProcesses = "cgroup.procs"
)
Variables ¶
var (
ErrDevicesUnsupported = errors.New("cgroup manager is not configured to set device rules")
)
var (
ErrV1NoUnified = errors.New("invalid configuration: cannot use unified on cgroup v1")
)
var ( // TestMode is set to true by unit tests that need "fake" cgroupfs. TestMode bool )
Functions ¶
func ConvertBlkIOToIOWeightValue ¶
将cgroup v1的BlkIOWeight转为cgroup v2 的IOWeight
func ConvertMemorySwapToCgroupV2Value ¶
转换cgroup v1的memory swap 到cgrop v2的 swap
func GetAllSubsystems ¶
func GetOwnCgroup ¶
GetOwnCgroup returns the relative path to the cgroup docker is running in.
func GetOwnCgroupPath ¶
func IsCgroup2UnifiedMode ¶
func IsCgroup2UnifiedMode() bool
func IsNotFound ¶
func NewNotFoundError ¶
func ParseCgroupFile ¶
ParseCgroupFile parses the given cgroup file, typically /proc/self/cgroup or /proc/<pid>/cgroup, into a map of subsystems to cgroup paths, e.g.
"cpu": "/user.slice/user-1000.slice" "pids": "/user.slice/user-1000.slice"
etc.
Note that for cgroup v2 unified hierarchy, there are no per-controller cgroup paths, so the resulting map will have a single element where the key is empty string ("") and the value is the cgroup path the <pid> is in.
func PathExists ¶
func RemovePath ¶
RemovePath aims to remove cgroup path. It does so recursively, by removing any subdirectories (sub-cgroups) first.
func RemovePaths ¶
RemovePaths iterates over the provided paths removing them.
Types ¶
type BlkioStatEntry ¶
type BlkioStats ¶
type BlkioStats struct {
// number of bytes transferred to and from the block device
IoServiceBytesRecursive []BlkioStatEntry `json:"io_service_bytes_recursive,omitempty"`
IoServicedRecursive []BlkioStatEntry `json:"io_serviced_recursive,omitempty"`
IoQueuedRecursive []BlkioStatEntry `json:"io_queue_recursive,omitempty"`
IoServiceTimeRecursive []BlkioStatEntry `json:"io_service_time_recursive,omitempty"`
IoWaitTimeRecursive []BlkioStatEntry `json:"io_wait_time_recursive,omitempty"`
IoMergedRecursive []BlkioStatEntry `json:"io_merged_recursive,omitempty"`
IoTimeRecursive []BlkioStatEntry `json:"io_time_recursive,omitempty"`
SectorsRecursive []BlkioStatEntry `json:"sectors_recursive,omitempty"`
PSI *PSIStats `json:"psi,omitempty"`
}
type CPUSetStats ¶
type CPUSetStats struct {
// List of the physical numbers of the CPUs on which processes
// in that cpuset are allowed to execute
CPUs []uint16 `json:"cpus,omitempty"`
// cpu_exclusive flag
CPUExclusive uint64 `json:"cpu_exclusive"`
// List of memory nodes on which processes in that cpuset
// are allowed to allocate memory
Mems []uint16 `json:"mems,omitempty"`
// mem_hardwall flag
MemHardwall uint64 `json:"mem_hardwall"`
// mem_exclusive flag
MemExclusive uint64 `json:"mem_exclusive"`
// memory_migrate flag
MemoryMigrate uint64 `json:"memory_migrate"`
// memory_spread page flag
MemorySpreadPage uint64 `json:"memory_spread_page"`
// memory_spread slab flag
MemorySpreadSlab uint64 `json:"memory_spread_slab"`
// memory_pressure
MemoryPressure uint64 `json:"memory_pressure"`
// sched_load balance flag
SchedLoadBalance uint64 `json:"sched_load_balance"`
// sched_relax_domain_level
SchedRelaxDomainLevel int64 `json:"sched_relax_domain_level"`
}
type CpuStats ¶
type CpuStats struct {
CpuUsage CpuUsage `json:"cpu_usage,omitempty"`
ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
PSI *PSIStats `json:"psi,omitempty"`
}
type CpuUsage ¶
type CpuUsage struct {
// Total CPU time consumed.
// Units: nanoseconds.
TotalUsage uint64 `json:"total_usage,omitempty"`
// Total CPU time consumed per core.
// Units: nanoseconds.
PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
// CPU time consumed per core in kernel mode
// Units: nanoseconds.
PercpuUsageInKernelmode []uint64 `json:"percpu_usage_in_kernelmode"`
// CPU time consumed per core in user mode
// Units: nanoseconds.
PercpuUsageInUsermode []uint64 `json:"percpu_usage_in_usermode"`
// Time spent by tasks of the cgroup in kernel mode.
// Units: nanoseconds.
UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
// Time spent by tasks of the cgroup in user mode.
// Units: nanoseconds.
UsageInUsermode uint64 `json:"usage_in_usermode"`
}
CpuUsage denotes the usage of a CPU. All CPU stats are aggregate since container inception.
type HugetlbStats ¶
type Manager ¶
type Manager interface {
// Apply creates a cgroup, if not yet created, and adds a process
// with the specified pid into that cgroup. A special value of -1
// can be used to merely create a cgroup.
Apply(pid int) error
// GetPids returns the PIDs of all processes inside the cgroup.
GetPids() ([]int, error)
// GetAllPids returns the PIDs of all processes inside the cgroup
// any all its sub-cgroups.
GetAllPids() ([]int, error)
// GetStats returns cgroups statistics.
GetStats() (*Stats, error)
// Freeze sets the freezer cgroup to the specified state.
Freeze(state config.FreezerState) error
// Destroy removes cgroup.
Destroy() error
// Path returns a cgroup path to the specified controller/subsystem.
// For cgroupv2, the argument is unused and can be empty.
Path(string) string
// Set sets cgroup resources parameters/limits. If the argument is nil,
// the resources specified during Manager creation (or the previous call
// to Set) are used.
Set(r *config.Resources) error
// GetPaths returns cgroup path(s) to save in a state file in order to
// restore later.
//
// For cgroup v1, a key is cgroup subsystem name, and the value is the
// path to the cgroup for this subsystem.
//
// For cgroup v2 unified hierarchy, a key is "", and the value is the
// unified path.
GetPaths() map[string]string
// GetCgroups returns the cgroup data as configured.
GetCgroups() (*config.Cgroup, error)
// GetFreezerState retrieves the current FreezerState of the cgroup.
GetFreezerState() (config.FreezerState, error)
// Exists returns whether the cgroup path exists or not.
Exists() bool
// OOMKillCount reports OOM kill count for the cgroup.
OOMKillCount() (uint64, error)
// GetEffectiveCPUs returns the effective CPUs of the cgroup, an empty
// value means that the cgroups cpuset subsystem/controller is not enabled.
GetEffectiveCPUs() string
}
type MemoryData ¶
type MemoryStats ¶
type MemoryStats struct {
// memory used for cache
Cache uint64 `json:"cache,omitempty"`
// usage of memory
Usage MemoryData `json:"usage,omitempty"`
// usage of memory + swap
SwapUsage MemoryData `json:"swap_usage,omitempty"`
// usage of swap only
SwapOnlyUsage MemoryData `json:"swap_only_usage,omitempty"`
// usage of kernel memory
KernelUsage MemoryData `json:"kernel_usage,omitempty"`
// usage of kernel TCP memory
KernelTCPUsage MemoryData `json:"kernel_tcp_usage,omitempty"`
// usage of memory pages by NUMA node
// see chapter 5.6 of memory controller documentation
PageUsageByNUMA PageUsageByNUMA `json:"page_usage_by_numa,omitempty"`
// if true, memory usage is accounted for throughout a hierarchy of cgroups.
UseHierarchy bool `json:"use_hierarchy"`
Stats map[string]uint64 `json:"stats,omitempty"`
PSI *PSIStats `json:"psi,omitempty"`
}
type Mount ¶
func GetCgroupMounts ¶
type NotFoundError ¶
type NotFoundError struct {
Subsystem string
}
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type PageUsageByNUMA ¶
type PageUsageByNUMA struct {
// Embedding is used as types can't be recursive.
PageUsageByNUMAInner
Hierarchical PageUsageByNUMAInner `json:"hierarchical,omitempty"`
}
type PageUsageByNUMAInner ¶
type Stats ¶
type Stats struct {
CpuStats CpuStats `json:"cpu_stats,omitempty"`
CPUSetStats CPUSetStats `json:"cpuset_stats,omitempty"`
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
PidsStats PidsStats `json:"pids_stats,omitempty"`
BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
// the map is in the format "size of hugepage: stats of the hugepage"
HugetlbStats map[string]HugetlbStats `json:"hugetlb_stats,omitempty"`
RdmaStats RdmaStats `json:"rdma_stats,omitempty"`
// the map is in the format "misc resource name: stats of the key"
MiscStats map[string]MiscStats `json:"misc_stats,omitempty"`
}
type ThrottlingData ¶
type ThrottlingData struct {
// Number of periods with throttling active
Periods uint64 `json:"periods,omitempty"`
// Number of periods when the container hit its throttling limit.
ThrottledPeriods uint64 `json:"throttled_periods,omitempty"`
// Aggregate time the container was throttled for in nanoseconds.
ThrottledTime uint64 `json:"throttled_time,omitempty"`
}