res

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CgroupV2

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

CgroupV2 manage resource by writing to linux cgroup file. Make sure that the host is using cgroupv2 before using this struct.

func NewCgroupV2

func NewCgroupV2(name string) (*CgroupV2, error)

NewCgroupV2 mkdir in cgroup path by given name.

func (*CgroupV2) AddSubGroup

func (cg *CgroupV2) AddSubGroup(name string) (*CgroupV2, error)

AddSubGroup will create a cgroup dir in current cgroup then add this to

func (*CgroupV2) Apply

func (cg *CgroupV2) Apply(pid int) error

Apply cgroup for pid.

func (*CgroupV2) Config

func (cg *CgroupV2) Config(config *ResourceConfig) error

Config set the cgroup resource limit.

func (*CgroupV2) Destroy

func (cg *CgroupV2) Destroy() error

Destroy remove current cgroup path, include its subcgroups. Do not use the CgroupV2 struct after executing Destroy or return an error.

func (*CgroupV2) GetSons

func (cg *CgroupV2) GetSons() []*CgroupV2

GetSons returns all subcgroups of current cgroup.

func (*CgroupV2) ReadState

func (cg *CgroupV2) ReadState() (*RunState, error)

ReadState returns the usage data product by process running.

type ResourceConfig

type ResourceConfig struct {
	CpuLimit    uint32
	MemoryLimit uint32
	PidsLimit   uint32
}

ResourceConfig records the limits of resource.

type ResourceManager

type ResourceManager interface {
	Apply(pid int) error
	Config(*ResourceConfig) error
	ReadState() (*RunState, error)
	Destroy() error
}

ResourceManager will be created to limit and monitor the resources' usage of processes.

type RunState

type RunState struct {
	CpuTime     uint32
	MemoryUsage uint32
	OOMKill     uint32
}

ResourceConfig records the resources' usage of processes put into ResourceManager.

Jump to

Keyboard shortcuts

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