cgroup

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2020 License: MIT Imports: 10 Imported by: 6

Documentation

Overview

Package cgroup provices builder to create multiple different cgroup-v1 sub groups under systemd defined path (i.e. /sys/fs/cgroup).

current avaliable cgroups are cpuacct, memory, pids not avaliable: cpu, cpuset, devices, freezer, net_cls, blkio, perf_event, net_prio, huge_tlb, rdma

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInitialized = errors.New("cgroup was not initialized")

ErrNotInitialized returned when trying to read from not initialized cgroup

Functions

func CreateSubCGroupPath

func CreateSubCGroupPath(group, prefix string) (string, error)

CreateSubCGroupPath creates path for sub-cgroup

func EnsureDirExists

func EnsureDirExists(path string) error

EnsureDirExists creates dir if not exists

func GetAllSubCgroup

func GetAllSubCgroup() (map[string]bool, error)

GetAllSubCgroup reads /proc/cgroups and get all avaliable sub-cgroup as set

Types

type Builder

type Builder struct {
	Prefix                string
	CPUAcct, Memory, Pids bool
}

Builder builds cgroup directories avaliable: cpuacct, memory, pids

func NewBuilder

func NewBuilder(prefix string) *Builder

NewBuilder return a dumb builder without any sub-cgroup

func (*Builder) Build

func (b *Builder) Build() (cg *CGroup, err error)

Build creates new cgrouup directories

func (*Builder) FilterByEnv

func (b *Builder) FilterByEnv() (*Builder, error)

FilterByEnv reads /proc/cgroups and filter out non-exists ones

func (*Builder) String

func (b *Builder) String() string

String prints the build properties

func (*Builder) WithCPUAcct

func (b *Builder) WithCPUAcct() *Builder

WithCPUAcct includes cpuacct cgroup

func (*Builder) WithMemory

func (b *Builder) WithMemory() *Builder

WithMemory includes memory cgroup

func (*Builder) WithPids

func (b *Builder) WithPids() *Builder

WithPids includes pids cgroup

type CGroup

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

CGroup is the combination of sub-cgroups

func (*CGroup) AddProc

func (c *CGroup) AddProc(pid int) error

AddProc writes cgroup.procs to all sub-cgroup

func (*CGroup) CpuacctUsage

func (c *CGroup) CpuacctUsage() (uint64, error)

CpuacctUsage read cpuacct.usage in ns

func (*CGroup) Destroy

func (c *CGroup) Destroy() error

Destroy removes dir for sub-cggroup, errors are ignored if remove one failed

func (*CGroup) FindMemoryStatProperty added in v0.1.3

func (c *CGroup) FindMemoryStatProperty(prop string) (uint64, error)

FindMemoryStatProperty find certain property from memory.stat

func (*CGroup) MemoryMaxUsageInBytes

func (c *CGroup) MemoryMaxUsageInBytes() (uint64, error)

MemoryMaxUsageInBytes read memory.max_usage_in_bytes

func (*CGroup) SetCpuacctUsage added in v0.1.2

func (c *CGroup) SetCpuacctUsage(i uint64) error

SetCpuacctUsage write cpuacct.usage in ns

func (*CGroup) SetMemoryLimitInBytes

func (c *CGroup) SetMemoryLimitInBytes(i uint64) error

SetMemoryLimitInBytes write memory.limit_in_bytes

func (*CGroup) SetMemoryMaxUsageInBytes added in v0.1.2

func (c *CGroup) SetMemoryMaxUsageInBytes(i uint64) error

SetMemoryMaxUsageInBytes write cpuacct.usage in ns

func (*CGroup) SetPidsMax

func (c *CGroup) SetPidsMax(i uint64) error

SetPidsMax write pids.max

type SubCGroup

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

SubCGroup is the sub-cgroup

func NewSubCGroup

func NewSubCGroup(p string) *SubCGroup

NewSubCGroup creates a sug CGroup

func (*SubCGroup) ReadFile added in v0.1.3

func (c *SubCGroup) ReadFile(name string) ([]byte, error)

ReadFile reads cgroup file and handles potential EINTR error while read to the slow device (cgroup)

func (*SubCGroup) ReadUint

func (c *SubCGroup) ReadUint(filename string) (uint64, error)

ReadUint read uint64 into given file

func (*SubCGroup) WriteFile added in v0.1.3

func (c *SubCGroup) WriteFile(name string, content []byte) error

WriteFile writes cgroup file and handles potential EINTR error while writes to the slow device (cgroup)

func (*SubCGroup) WriteUint

func (c *SubCGroup) WriteUint(filename string, i uint64) error

WriteUint writes uint64 into given file

Jump to

Keyboard shortcuts

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