docker

package
v4.26.9 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: BSD-3-Clause Imports: 13 Imported by: 5

Documentation

Overview

SPDX-License-Identifier: BSD-3-Clause

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDockerNotAvailable = errors.New("docker not available")
	ErrCgroupNotAvailable = errors.New("cgroup not available")
)

Functions

func CgroupCPUDockerUsageWithContext

func CgroupCPUDockerUsageWithContext(ctx context.Context, containerID string) (float64, error)

func CgroupCPUUsage

func CgroupCPUUsage(containerID, base string) (float64, error)

CgroupCPUUsage returns specified cgroup id CPU usage. containerID is same as docker id if you use docker. If you use container via systemd.slice, you could use containerID = docker-<container id>.scope and base=/sys/fs/cgroup/cpuacct/system.slice/ on cgroup v1 or base=/sys/fs/cgroup/system.slice/ on cgroup v2. The cgroup hierarchy (v1 or v2) is detected automatically through /sys/fs/cgroup/cgroup.controllers.

func CgroupCPUUsageDocker

func CgroupCPUUsageDocker(containerID string) (float64, error)

func CgroupCPUUsageWithContext

func CgroupCPUUsageWithContext(ctx context.Context, containerID, base string) (float64, error)

func GetDockerIDList

func GetDockerIDList() ([]string, error)

GetDockerIDList returns a list of DockerID. This requires certain permission.

func GetDockerIDListWithContext

func GetDockerIDListWithContext(ctx context.Context) ([]string, error)

Types

type CgroupCPUStat

type CgroupCPUStat struct {
	cpu.TimesStat
	Usage float64
}

func CgroupCPU

func CgroupCPU(containerID, base string) (*CgroupCPUStat, error)

CgroupCPU returns specified cgroup id CPU status. containerID is same as docker id if you use docker. If you use container via systemd.slice, you could use containerID = docker-<container id>.scope and base=/sys/fs/cgroup/cpuacct/system.slice/ on cgroup v1 or base=/sys/fs/cgroup/system.slice/ on cgroup v2. The cgroup hierarchy (v1 or v2) is detected automatically through /sys/fs/cgroup/cgroup.controllers.

func CgroupCPUDocker

func CgroupCPUDocker(containerID string) (*CgroupCPUStat, error)

func CgroupCPUDockerWithContext

func CgroupCPUDockerWithContext(ctx context.Context, containerID string) (*CgroupCPUStat, error)

func CgroupCPUOwn added in v4.26.9

func CgroupCPUOwn() (*CgroupCPUStat, error)

CgroupCPUOwn returns the CPU status of the cgroup the calling process belongs to. Unlike CgroupCPUDocker it needs no container ID, so it works from inside a container that cannot see its own cgroup name, which is the default for docker on cgroup v2. The CPU field of the result is "own".

func CgroupCPUOwnWithContext added in v4.26.9

func CgroupCPUOwnWithContext(ctx context.Context) (*CgroupCPUStat, error)

func CgroupCPUWithContext

func CgroupCPUWithContext(ctx context.Context, containerID, base string) (*CgroupCPUStat, error)

type CgroupDockerStat

type CgroupDockerStat struct {
	ContainerID string `json:"containerID"`
	Name        string `json:"name"`
	Image       string `json:"image"`
	Status      string `json:"status"`
	Running     bool   `json:"running"`
}

func GetDockerStat

func GetDockerStat() ([]CgroupDockerStat, error)

GetDockerStat returns a list of Docker basic stats. This requires certain permission.

func GetDockerStatWithContext

func GetDockerStatWithContext(ctx context.Context) ([]CgroupDockerStat, error)

func (CgroupDockerStat) String

func (c CgroupDockerStat) String() string

type CgroupMemStat

type CgroupMemStat struct {
	ContainerID             string `json:"containerID"`
	Cache                   uint64 `json:"cache"`
	RSS                     uint64 `json:"rss"`
	RSSHuge                 uint64 `json:"rssHuge"`
	MappedFile              uint64 `json:"mappedFile"`
	Pgpgin                  uint64 `json:"pgpgin"`
	Pgpgout                 uint64 `json:"pgpgout"`
	Pgfault                 uint64 `json:"pgfault"`
	Pgmajfault              uint64 `json:"pgmajfault"`
	InactiveAnon            uint64 `json:"inactiveAnon"`
	ActiveAnon              uint64 `json:"activeAnon"`
	InactiveFile            uint64 `json:"inactiveFile"`
	ActiveFile              uint64 `json:"activeFile"`
	Unevictable             uint64 `json:"unevictable"`
	HierarchicalMemoryLimit uint64 `json:"hierarchicalMemoryLimit"`
	TotalCache              uint64 `json:"totalCache"`
	TotalRSS                uint64 `json:"totalRss"`
	TotalRSSHuge            uint64 `json:"totalRssHuge"`
	TotalMappedFile         uint64 `json:"totalMappedFile"`
	TotalPgpgIn             uint64 `json:"totalPgpgin"`
	TotalPgpgOut            uint64 `json:"totalPgpgout"`
	TotalPgFault            uint64 `json:"totalPgfault"`
	TotalPgMajFault         uint64 `json:"totalPgmajfault"`
	TotalInactiveAnon       uint64 `json:"totalInactiveAnon"`
	TotalActiveAnon         uint64 `json:"totalActiveAnon"`
	TotalInactiveFile       uint64 `json:"totalInactiveFile"`
	TotalActiveFile         uint64 `json:"totalActiveFile"`
	TotalUnevictable        uint64 `json:"totalUnevictable"`
	MemUsageInBytes         uint64 `json:"memUsageInBytes"`
	MemMaxUsageInBytes      uint64 `json:"memMaxUsageInBytes"`
	MemLimitInBytes         uint64 `json:"memoryLimitInBytes"`
	MemFailCnt              uint64 `json:"memoryFailcnt"`
}

func CgroupMem

func CgroupMem(containerID, base string) (*CgroupMemStat, error)

CgroupMem returns specified cgroup id memory status. containerID is same as docker id if you use docker. If you use container via systemd.slice, you could use containerID = docker-<container id>.scope and base=/sys/fs/cgroup/memory/system.slice/ on cgroup v1 or base=/sys/fs/cgroup/system.slice/ on cgroup v2. The cgroup hierarchy (v1 or v2) is detected automatically through /sys/fs/cgroup/cgroup.controllers.

func CgroupMemDocker

func CgroupMemDocker(containerID string) (*CgroupMemStat, error)

func CgroupMemDockerWithContext

func CgroupMemDockerWithContext(ctx context.Context, containerID string) (*CgroupMemStat, error)

func CgroupMemOwn added in v4.26.9

func CgroupMemOwn() (*CgroupMemStat, error)

CgroupMemOwn returns the memory status of the cgroup the calling process belongs to. Unlike CgroupMemDocker it needs no container ID, so it works from inside a container that cannot see its own cgroup name, which is the default for docker on cgroup v2. The ContainerID of the result is "own".

func CgroupMemOwnWithContext added in v4.26.9

func CgroupMemOwnWithContext(ctx context.Context) (*CgroupMemStat, error)

func CgroupMemWithContext

func CgroupMemWithContext(ctx context.Context, containerID, base string) (*CgroupMemStat, error)

func (CgroupMemStat) String

func (m CgroupMemStat) String() string

Jump to

Keyboard shortcuts

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