Documentation
¶
Index ¶
- Constants
- Variables
- func ContainerIDForPID(pid int) (string, error)
- func GetHostname() (string, error)
- func ScrapeAllCgroups() (map[string]*ContainerCgroup, error)
- type CgroupIOStat
- type CgroupMemStat
- type CgroupTimesStat
- type ContainerCgroup
- func (c ContainerCgroup) CPU() (*CgroupTimesStat, error)
- func (c ContainerCgroup) CPULimit() (float64, error)
- func (c ContainerCgroup) CPUNrThrottled() (uint64, error)
- func (c ContainerCgroup) ContainerStartTime() (int64, error)
- func (c ContainerCgroup) IO() (*CgroupIOStat, error)
- func (c ContainerCgroup) Mem() (*CgroupMemStat, error)
- func (c ContainerCgroup) MemLimit() (uint64, error)
- func (c ContainerCgroup) ParseSingleStat(target, file string) (uint64, error)
Constants ¶
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 ¶
var ( // ErrDockerNotAvailable is returned if Docker is not running on the current machine. // We'll use this when configuring the DockerUtil so we don't error on non-docker machines. ErrDockerNotAvailable = errors.New("docker not available") // ErrDockerNotCompiled is returned if docker support is not compiled in. // User classes should handle that case as gracefully as possible. ErrDockerNotCompiled = errors.New("docker support not compiled in") )
var ( // ErrMissingTarget is an error set when a cgroup target is missing. ErrMissingTarget = errors.New("Missing cgroup target") )
var ErrNotImplemented = errors.New("not implemented yet")
ErrNotImplemented is the "not implemented" error given by `gopsutil` when an OS doesn't support and API. Unfortunately it's in an internal package so we can't import it so we'll copy it here.
Functions ¶
func ContainerIDForPID ¶
ContainerIDForPID is a lighter version of CgroupsForPids to only retrieve the container ID for origin detection. Returns container id as a string, empty if the PID is not in a container.
func ScrapeAllCgroups ¶
func ScrapeAllCgroups() (map[string]*ContainerCgroup, error)
ScrapeAllCgroups returns ContainerCgroup for every container that's in a Cgroup. This version iterates on /{host/}proc to retrieve processes out of the namespace. We return as a map[containerID]Cgroup for easy look-up.
Types ¶
type CgroupIOStat ¶
CgroupIOStat store I/O statistics about a cgroup.
type CgroupMemStat ¶
type CgroupMemStat struct { ContainerID string Cache uint64 Swap uint64 // See SwapPresent to make sure it's a real zero SwapPresent bool 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 HierarchicalMemSWLimit uint64 // One can safely assume 0 == absent 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 MemFailCnt uint64 }
CgroupMemStat stores memory statistics about a cgroup.
type CgroupTimesStat ¶
CgroupTimesStat stores CPU times for a cgroup. Unit is userspace scheduling unit (USER_HZ, usually 1/100)
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 ¶
func (c ContainerCgroup) CPU() (*CgroupTimesStat, error)
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) CPUNrThrottled ¶
func (c ContainerCgroup) CPUNrThrottled() (uint64, error)
CPUNrThrottled 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) IO ¶
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.
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.