docker

package
v0.99.35 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2017 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingTarget = errors.New("Missing cgroup target")
	ErrFildNotFound  = errors.New("cgroup file is missing")
)
View Source
var (
	ErrDockerNotAvailable = errors.New("docker not available")
)

Functions

func CgroupsForPids

func CgroupsForPids(pids []int32) (map[string]*ContainerCgroup, error)

CgroupsForPids returns ContainerCgroup for every container that's in a Cgroup. We return as a map[containerID]Cgroup for easy look-up.

func ContainersByPID

func ContainersByPID(pids []int32) (map[int32]*Container, error)

Generates a mapping of PIDs to container metadata. Optimized to limit the number of syscalls for each PID for just enough to get the data we need. Only supports Docker containers for now but the bulk of the logic is around cgroups so we could support other types without too much trouble.

func GetHostname added in v0.99.33

func GetHostname() (string, error)

Types

type CgroupIOStat added in v0.99.34

type CgroupIOStat struct {
	ContainerID string
	ReadBytes   uint64
	WriteBytes  uint64
}

type CgroupMemStat

type CgroupMemStat struct {
	ContainerID             string
	Cache                   uint64
	RSS                     uint64
	RSSHuge                 uint64
	MappedFile              uint64
	Pgpgin                  uint64
	Pgpgout                 uint64
	Pgfault                 uint64
	Pgmajfault              uint64
	InactiveAnon            uint64
	ActiveAnon              uint64
	InactiveFile            uint64
	ActiveFile              uint64
	Unevictable             uint64
	HierarchicalMemoryLimit uint64
	TotalCache              uint64
	TotalRSS                uint64
	TotalRSSHuge            uint64
	TotalMappedFile         uint64
	TotalPgpgIn             uint64
	TotalPgpgOut            uint64
	TotalPgFault            uint64
	TotalPgMajFault         uint64
	TotalInactiveAnon       uint64
	TotalActiveAnon         uint64
	TotalInactiveFile       uint64
	TotalActiveFile         uint64
	TotalUnevictable        uint64
	MemUsageInBytes         uint64
	MemMaxUsageInBytes      uint64
	MemLimitInBytes         uint64
	MemFailCnt              uint64
}

type CgroupTimesStat

type CgroupTimesStat struct {
	ContainerID string
	System      float64
	User        float64
}

type Container

type Container struct {
	Type       string
	ID         string
	Name       string
	Image      string
	ImageID    string
	CPULimit   float64
	MemLimit   uint64
	Created    int64
	State      string
	Health     string
	ReadBytes  uint64
	WriteBytes uint64
}

func GetDockerContainers

func GetDockerContainers() ([]*Container, error)

GetDockerContainers returns a list of Docker info for active containers using the Docker API. This requires the running user to be in the "docker" user group or have access to /tmp/docker.sock.

type ContainerCgroup

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

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 If the limits files aren't available (on older version) then we'll return the default value of 100.

func (ContainerCgroup) IO added in v0.99.34

func (c ContainerCgroup) IO() (*CgroupIOStat, error)

IO returns the disk read and write bytes stats for this cgroup. 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) Mem

func (c ContainerCgroup) Mem() (*CgroupMemStat, error)

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

Jump to

Keyboard shortcuts

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