cgroups

package
v1.9.1 Latest Latest
Warning

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

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

Documentation

Overview

Package cgroups provides functions to parse cgroup information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlatMap

type FlatMap map[string]Value

FlatMap returns the flat map of the cgroup values.

func ParseFlatMapValues

func ParseFlatMapValues(r io.Reader) (FlatMap, error)

ParseFlatMapValues parses the cgroup values from the flat map.

Flat keyed:

KEY0 VAL0\n KEY1 VAL1\n ...

type NestedKeyed

type NestedKeyed map[string]FlatMap

NestedKeyed returns the nested keyed map of the cgroup values.

func ParseNestedKeyedValues

func ParseNestedKeyedValues(r io.Reader) (NestedKeyed, error)

ParseNestedKeyedValues parses the cgroup values from the nested keyed map.

Nested keyed:

KEY0 SUB_KEY0=VAL00 SUB_KEY1=VAL01... KEY1 SUB_KEY0=VAL10 SUB_KEY1=VAL11... ...

type Node

type Node struct {
	Children map[string]*Node

	CgroupEvents  FlatMap
	CgroupFreeze  Value
	CgroupProcs   Values
	CgroupStat    FlatMap
	CgroupThreads Values

	// Resolved externally into process names.
	CgroupProcsResolved []RawValue

	CPUIdle       Value
	CPUMax        Values
	CPUMaxBurst   Value
	CPUPressure   NestedKeyed
	CPUStat       FlatMap
	CPUStatLocal  FlatMap
	CPUWeight     Value
	CPUWeightNice Value

	CPUSetCPUs          RawValue
	CPUSetCPUsEffective RawValue
	CPUSetMems          RawValue
	CPUSetMemsEffective RawValue

	IOBFQWeight FlatMap
	IOMax       NestedKeyed
	IOPressure  NestedKeyed
	IOStat      NestedKeyed

	MemoryCurrent     Value
	MemoryEvents      FlatMap
	MemoryEventsLocal FlatMap
	MemoryHigh        Value
	MemoryLow         Value
	MemoryMax         Value
	MemoryMin         Value
	MemoryNUMAStat    NestedKeyed
	MemoryOOMGroup    Value
	MemoryPeak        Value
	MemoryPressure    NestedKeyed
	MemoryStat        FlatMap

	MemorySwapCurrent Value
	MemorySwapEvents  FlatMap
	MemorySwapHigh    Value
	MemorySwapMax     Value
	MemorySwapPeak    Value

	PidsCurrent Value
	PidsEvents  FlatMap
	PidsMax     Value
	PidsPeak    Value
}

Node represents a cgroup node.

func (*Node) Parse

func (n *Node) Parse(filename string, r io.Reader) error

Parse the cgroup information by filename from the reader.

func (*Node) ResolveNames

func (n *Node) ResolveNames(nameMap map[string]string)

ResolveNames resolves the names of the node and its children.

func (*Node) SortedChildren

func (n *Node) SortedChildren() []string

SortedChildren returns the sorted children of the node.

func (*Node) Walk

func (n *Node) Walk(fn func(*Node))

Walk the node.

type RawValue

type RawValue string

RawValue is a raw cgroup value (without any parsing).

func ParseRawValue

func ParseRawValue(r io.Reader) (RawValue, error)

ParseRawValue parses the raw cgroup value.

type Tree

type Tree struct {
	Root *Node
}

Tree represents a cgroup tree.

func TreeFromTarGz

func TreeFromTarGz(r io.Reader) (*Tree, error)

TreeFromTarGz builds a crgroup tree from the tar.gz reader.

It is assumed to work with output of `talosctl cp /sys/fs/cgroup -`.

func (*Tree) Find

func (t *Tree) Find(directoryPath string) *Node

Find the node by directory path.

func (*Tree) ResolveNames

func (t *Tree) ResolveNames(nameMap map[string]string)

ResolveNames resolves the names of the node and its children.

func (*Tree) Walk

func (t *Tree) Walk(fn func(*Node))

Walk the tree.

type Value

type Value struct {
	Val   int64
	Frac  int
	IsMax bool
	IsSet bool
}

Value represents a cgroup value.

Value might represent 'max' value.

func ParseValue

func ParseValue(s string) (Value, error)

ParseValue parses the cgroup value from the string.

func (Value) DivideBy

func (v Value) DivideBy(other Value) Value

DivideBy returns the value divided by another value in percentage.

a.DivideBy(b) = a / b * 100.

func (Value) HumanizeIBytes

func (v Value) HumanizeIBytes() string

HumanizeIBytes returns the humanized bytes representation of the cgroup value.

func (Value) String

func (v Value) String() string

String returns the string representation of the cgroup value.

func (Value) UsecToDuration

func (v Value) UsecToDuration() string

UsecToDuration returns the duration representation of the cgroup value in microseconds.

type Values

type Values []Value

Values represents a list of cgroup values.

func ParseNewlineSeparatedValues

func ParseNewlineSeparatedValues(r io.Reader) (Values, error)

ParseNewlineSeparatedValues parses the cgroup values from the newline separated string.

New-line separated values (when only one value can be written at once)

VAL0\n VAL1\n ...

func ParseSpaceSeparatedValues

func ParseSpaceSeparatedValues(r io.Reader) (Values, error)

ParseSpaceSeparatedValues parses the cgroup values from the space separated string.

Space separated values (when read-only or multiple values can be written at once)

VAL0 VAL1 ...\n.

Jump to

Keyboard shortcuts

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