cgroup

package
v0.0.0-...-cc86db0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCfsNotEnabled = errors.New("Make sure that CONFIG_CFS_BANDWIDTH option is enabled in your kernel")
	ErrRtNotEnabled  = errors.New("Make sure that CONFIG_RT_GROUP_SCHED option is enabled in your kernel")
)
View Source
var (
	ErrCgroupRemoved = errors.New("Unable to continue. Control group already removed")
)

Functions

func DestroyCgroup

func DestroyCgroup(path string) error

func GetCgroupPathByPid

func GetCgroupPathByPid(pid int, subsystem string) (string, error)

func GetEnabledSubsystems

func GetEnabledSubsystems() (map[string]int, error)

func GetProcessCgroups

func GetProcessCgroups(pid int) (map[string]string, error)

func GetSubsystemMountpoint

func GetSubsystemMountpoint(subsystem string) (string, error)

func IsCgroupInitError

func IsCgroupInitError(err error) bool

func IsCgroupsNotFoundError

func IsCgroupsNotFoundError(err error) bool

func IsUnsupportedError

func IsUnsupportedError(err error) bool

func NewCgroupInitError

func NewCgroupInitError(subsystem string, err error) error

func NewCgroupsNotFoundError

func NewCgroupsNotFoundError(pid int) error

func NewUnsupportedError

func NewUnsupportedError(subsystem string) error

func TestCgroup

func TestCgroup(t *testing.T)

Types

type Cgroup

type Cgroup interface {
	Set(*Config) error

	Get(*Config) error

	GetPath() string
}

func LookupCgroupByPid

func LookupCgroupByPid(pid int, subsystem string) (Cgroup, error)

func NewCpuGroup

func NewCpuGroup(subpath string, pid int) (Cgroup, error)

func NewGroup

func NewGroup(subpath string, subsystem string, pid int) (Cgroup, error)

func NewMemoryGroup

func NewMemoryGroup(subpath string, pid int) (Cgroup, error)

type CgroupInitError

type CgroupInitError struct {
	Subsystem string
	Err       error
}

func (*CgroupInitError) Error

func (e *CgroupInitError) Error() string

type CgroupsNotFoundError

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

func (*CgroupsNotFoundError) Error

func (e *CgroupsNotFoundError) Error() string

type Config

type Config struct {
	// CPU 使用率权重
	CpuShares int64 `json:"cpu_shares"`

	// 以下两个参数用于限制CPU最高使用率
	CpuQuota  int64 `json:"cpu_quota"`
	CpuPeriod int64 `json:"cpu_period"`

	// 以下两个参数用于设置CPU最高使用率
	CpuRtRuntime int64 `json:"cpu_rt_runtime"`
	CpuRtPeriod  int64 `json:"cpu_rt_period"`

	//限制最大内存使用量
	MemoryLimit int64 `json:"memory_quota"`
}

type CpuGroup

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

func (*CpuGroup) Get

func (g *CpuGroup) Get(c *Config) error

func (*CpuGroup) GetPath

func (g *CpuGroup) GetPath() string

func (*CpuGroup) Set

func (g *CpuGroup) Set(c *Config) error

type CpuStats

type CpuStats struct {
	CpuUsage       CpuUsage       `json:"cpu_usage,omitempty"`
	ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
}

type CpuUsage

type CpuUsage struct {
	// Total CPU time consumed (in nanoseconds).
	TotalUsage uint64 `json:"total_usage,omitempty"`

	// Total CPU time consumed per core (in nanoseconds).
	PercpuUsage []uint64 `json:"percpu_usage,omitempty"`

	// Time spent by tasks of the cgroup in kernel mode (in nanoseconds).
	UsageInKernelmode uint64 `json:"usage_in_kernelmode"`

	// Time spent by tasks of the cgroup in user mode (in nanoseconds).
	UsageInUsermode uint64 `json:"usage_in_usermode"`
}

type Manager

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

The wrapper around the several control groups to more convenient using.

func LoadManager

func LoadManager(pid int) (*Manager, error)

func NewManager

func NewManager(pid int, subpath string, subsystems ...string) (*Manager, error)

func (*Manager) Destroy

func (m *Manager) Destroy() error

func (*Manager) Get

func (m *Manager) Get(c *Config) error

func (*Manager) GetPid

func (m *Manager) GetPid() int

func (*Manager) Set

func (m *Manager) Set(c *Config) error

type MemoryGroup

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

func (*MemoryGroup) Get

func (g *MemoryGroup) Get(c *Config) error

func (*MemoryGroup) GetPath

func (g *MemoryGroup) GetPath() string

func (*MemoryGroup) Set

func (g *MemoryGroup) Set(c *Config) error

type Stats

type Stats struct {
	CpuStats CpuStats `json:"cpu_stats,omitempty"`
}

type ThrottlingData

type ThrottlingData struct {
	// Number of periods with throttling active.
	Periods uint64 `json:"nr_periods,omitempty"`

	// Number of times when the tasks have been throttled.
	ThrottledPeriods uint64 `json:"nr_throttled,omitempty"`

	// Aggregate time when the tasks have been throttled (in nanoseconds).
	ThrottledTime uint64 `json:"throttled_time,omitempty"`
}

type UnsupportedError

type UnsupportedError struct {
	Subsystem string
}

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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