cgroup

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const NanoToUserHZDivisor float64 = 1e9 / 100

NanoToUserHZDivisor holds the divisor to convert cpu.usage to the same unit as cpu.system (USER_HZ = 1/100) TODO: get USER_HZ from gopsutil? Needs to patch it

Variables

View Source
var (

	// ErrMissingTarget is an error set when a cgroup target is missing.
	ErrMissingTarget = errors.New("Missing cgroup target")
)

Functions

func GetFileDescriptorLen

func GetFileDescriptorLen(pid int) (int, error)

GetFileDescriptorLen gets the number of open file descriptors for a given pid

Types

type ContainerCgroup

type ContainerCgroup struct {
	ContainerID string
	Pids        []int32
	Paths       map[string]string
	Mounts      map[string]string
}

ContainerCgroup is a structure that stores paths and mounts for a cgroup. It provides several methods for collecting stats about the cgroup using the paths and mounts metadata.

func (ContainerCgroup) CPU

CPU returns the CPU status for this cgroup instance If the cgroup file does not exist then we just log debug return nothing.

func (ContainerCgroup) CPULimit

func (c ContainerCgroup) CPULimit() (float64, error)

CPULimit would show CPU limit for this cgroup. It does so by checking the cpu period and cpu quota config if a user does this:

docker run --cpus='0.5' ubuntu:latest

we should return 50% for that container.

However cfs_period_us is per CPU, which means that

docker run --cpu='2' ubuntu:latest

Will yield 200% (cfs_period_us = 100000, cfs_quota_us = 200000)

If the limits files aren't available (on older version) then we'll return the default value of numCPU * 100.

func (ContainerCgroup) CPUPeriods

func (c ContainerCgroup) CPUPeriods() (throttledNr uint64, throttledTime float64, err error)

CPUPeriods returns the number of times the cgroup has been throttle/limited because of CPU quota / limit If the cgroup file does not exist then we just log debug and return 0.

func (ContainerCgroup) ContainerStartTime

func (c ContainerCgroup) ContainerStartTime() (int64, error)

ContainerStartTime gets the stat for cgroup directory and use the mtime for that dir to determine the start time for the container this should work because the cgroup dir for the container would be created only when it's started

func (ContainerCgroup) FailedMemoryCount

func (c ContainerCgroup) FailedMemoryCount() (uint64, error)

FailedMemoryCount returns the number of times this cgroup reached its memory limit, if it exists. If the file does not exist or there is no limit, then this will default to 0

func (ContainerCgroup) IO

IO returns the disk read and write bytes stats for this cgroup. tested in DiskMappingTestSuite.TestContainerCgroupIO Format:

8:0 Read 49225728 8:0 Write 9850880 8:0 Sync 0 8:0 Async 59076608 8:0 Total 59076608 252:0 Read 49094656 252:0 Write 9850880 252:0 Sync 0 252:0 Async 58945536 252:0 Total 58945536

func (ContainerCgroup) KernelMemoryUsage

func (c ContainerCgroup) KernelMemoryUsage() (uint64, error)

KernelMemoryUsage returns the number of bytes of kernel memory used by this cgroup, if it exists. If the file does not exist or there is an error, then this will default to 0

func (ContainerCgroup) Mem

Mem returns the memory statistics for a Cgroup. If the cgroup file is not available then we return an empty stats file.

func (ContainerCgroup) MemLimit

func (c ContainerCgroup) MemLimit() (uint64, error)

MemLimit returns the memory limit of the cgroup, if it exists. If the file does not exist or there is no limit then this will default to 0.

func (ContainerCgroup) ParseSingleStat

func (c ContainerCgroup) ParseSingleStat(target, file string) (uint64, error)

ParseSingleStat reads and converts a single-value cgroup stat file content to uint64.

func (ContainerCgroup) SoftMemLimit

func (c ContainerCgroup) SoftMemLimit() (uint64, error)

SoftMemLimit returns the soft memory limit of the cgroup, if it exists. If the file does not exist or there is no limit then this will default to 0.

func (ContainerCgroup) ThreadCount

func (c ContainerCgroup) ThreadCount() (uint64, error)

ThreadCount returns the number of threads in the pid cgroup linked to the container. ref: https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt

Although the metric is called `pid.current`, it also tracks threads, and not only task-group-pids

func (ContainerCgroup) ThreadLimit

func (c ContainerCgroup) ThreadLimit() (uint64, error)

ThreadLimit returns the thread count limit in the pid cgroup linked to the container. ref: https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt

If `max` is found, the method returns 0 as-in "no limit"

Jump to

Keyboard shortcuts

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