cgroup

package
v1.1.0-beta.0...-d5b6b69 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCPUPeriodAndQuota

func GetCPUPeriodAndQuota() (period int64, quota int64, err error)

GetCPUPeriodAndQuota returns CPU period and quota time of cgroup.

func GetMemoryInactiveFileUsage

func GetMemoryInactiveFileUsage() (usage uint64, err error)

GetMemoryInactiveFileUsage attempts to retrieve the cgroup memory usage value (in bytes) for the current process.

func GetMemoryLimit

func GetMemoryLimit() (limit uint64, err error)

GetMemoryLimit attempts to retrieve the cgroup memory limit for the current process.

func GetMemoryUsage

func GetMemoryUsage() (usage uint64, err error)

GetMemoryUsage attempts to retrieve the cgroup memory usage value (in bytes) for the current process.

func InContainer

func InContainer() bool

InContainer returns true if the process is running in a container.

func SetGOMAXPROCS

func SetGOMAXPROCS() (func(), error)

SetGOMAXPROCS is to set GOMAXPROCS to the number of CPUs.

Types

type CPUQuotaStatus

type CPUQuotaStatus int

CPUQuotaStatus presents the status of how CPU quota is used

const (
	// CPUQuotaUndefined is returned when CPU quota is undefined
	CPUQuotaUndefined CPUQuotaStatus = iota
	// CPUQuotaUsed is returned when a valid CPU quota can be used
	CPUQuotaUsed
	// CPUQuotaMinUsed is return when CPU quota is smaller than the min value
	CPUQuotaMinUsed
)

func CPUQuotaToGOMAXPROCS

func CPUQuotaToGOMAXPROCS(minValue int) (int, CPUQuotaStatus, error)

CPUQuotaToGOMAXPROCS converts the CPU quota applied to the calling process to a valid GOMAXPROCS value.

type CPUUsage

type CPUUsage struct {
	// System time and user time taken by this cgroup or process. In nanoseconds.
	Stime, Utime uint64
	// CPU period and quota for this process, in microseconds. This cgroup has
	// access to up to (quota/period) proportion of CPU resources on the system.
	// For instance, if there are 4 CPUs, quota = 150000, period = 100000,
	// this cgroup can use around ~1.5 CPUs, or 37.5% of total scheduler time.
	// If quota is -1, it's unlimited.
	Period, Quota int64
	// NumCPUs is the number of CPUs in the system. Always returned even if
	// not called from a cgroup.
	NumCPU int
}

CPUUsage returns CPU usage and quotas for an entire cgroup.

func GetCgroupCPU

func GetCgroupCPU() (CPUUsage, error)

GetCgroupCPU returns the CPU usage and quota for the current cgroup.

func (CPUUsage) CPUShares

func (c CPUUsage) CPUShares() float64

CPUShares returns the number of CPUs this cgroup can be expected to max out. If there's no limit, NumCPU is returned.

type Version

type Version int

Version represents the cgroup version.

const (
	Unknown Version = 0
	V1      Version = 1
	V2      Version = 2
)

cgroup versions.

func GetCgroupMemLimit

func GetCgroupMemLimit() (uint64, Version, error)

GetCgroupMemLimit attempts to retrieve the cgroup memory limit for the current process, and return cgroup version too.

Jump to

Keyboard shortcuts

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