system

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 29 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ExecNSTool   string = "/usr/local/bin/nstools"
	ExecSidekick string = "/usr/local/bin/sidekick"
	NSActGet     string = "get"
	NSActRun     string = "run"
	NSActExist   string = "exist"
)

Variables

View Source
var ErrFileTooBig = errors.New("File Size over limit")

Functions

func PopulateSystemStats

func PopulateSystemStats(data *share.CLUSStats, stats *share.ContainerStats)

func UpdateStats

func UpdateStats(cs *share.ContainerStats, memory, cpu, cpuSystem uint64)

Types

type CgroupMemoryStats

type CgroupMemoryStats struct {
	// memory used reference by "kubectl top"
	WorkingSet uint64 `json:"working_set,omitempty"`
	// memory used for cache
	Cache uint64 `json:"cache,omitempty"`
	// usage of memory
	Usage MemoryData `json:"usage,omitempty"`
	// usage of memory + swap
	SwapUsage MemoryData `json:"swap_usage,omitempty"`
	// usage of kernel memory
	KernelUsage MemoryData `json:"kernel_usage,omitempty"`
	// usage of kernel TCP memory
	KernelTCPUsage MemoryData `json:"kernel_tcp_usage,omitempty"`
	// if true, memory usage is accounted for throughout a hierarchy of cgroups.
	UseHierarchy bool `json:"use_hierarchy"`

	Stats map[string]uint64 `json:"stats,omitempty"`
}

type CpuStats

type CpuStats struct {
	CpuUsage       CpuUsage       `json:"cpu_usage,omitempty"`
	ThrottlingData ThrottlingData `json:"throttling_data,omitempty"`
}

type CpuUsage

type CpuUsage struct {
	// Total CPU time consumed.
	// Units: nanoseconds.
	TotalUsage uint64 `json:"total_usage,omitempty"`
	// Total CPU time consumed per core.
	// Units: nanoseconds.
	PercpuUsage []uint64 `json:"percpu_usage,omitempty"`
	// CPU time consumed per core in kernel mode
	// Units: nanoseconds.
	PercpuUsageInKernelmode []uint64 `json:"percpu_usage_in_kernelmode"`
	// CPU time consumed per core in user mode
	// Units: nanoseconds.
	PercpuUsageInUsermode []uint64 `json:"percpu_usage_in_usermode"`
	// Time spent by tasks of the cgroup in kernel mode.
	// Units: nanoseconds.
	UsageInKernelmode uint64 `json:"usage_in_kernelmode"`
	// Time spent by tasks of the cgroup in user mode.
	// Units: nanoseconds.
	UsageInUsermode uint64 `json:"usage_in_usermode"`
}

type MemoryData

type MemoryData struct {
	Usage    uint64 `json:"usage,omitempty"`
	MaxUsage uint64 `json:"max_usage,omitempty"`
	Failcnt  uint64 `json:"failcnt"`
	Limit    uint64 `json:"limit"`
}

from github.com\opencontainers\runc\libcontainer\cgroups\stats.go

type MemoryPressureCallback

type MemoryPressureCallback func(report *MemoryPressureReport)

type MemoryPressureReport

type MemoryPressureReport struct {
	// pressure level
	Level uint64 `json:"level"`
	// memory stats
	Stats CgroupMemoryStats `json:"stats"`
}

type NSCallback

type NSCallback func(params interface{})

type SystemTools

type SystemTools struct {
	// contains filtered or unexported fields
}

func NewSystemTools

func NewSystemTools() *SystemTools

func (*SystemTools) AddToolProcess

func (s *SystemTools) AddToolProcess(pgid, pid int, exec, cmds string)

func (*SystemTools) CGroupMemoryStatReset

func (s *SystemTools) CGroupMemoryStatReset(threshold uint64) bool

func (*SystemTools) CallNamespaceFunc

func (s *SystemTools) CallNamespaceFunc(nsid int, nstypes []string, cb NSCallback, params interface{}) error

func (*SystemTools) CallNetNamespaceFunc

func (s *SystemTools) CallNetNamespaceFunc(pid int, cb NSCallback, params interface{}) error

func (*SystemTools) CallNetNamespaceFuncWithoutLock

func (s *SystemTools) CallNetNamespaceFuncWithoutLock(pid int, cb NSCallback, params interface{}) error

func (*SystemTools) CheckHostProgram

func (s *SystemTools) CheckHostProgram(prog string, pid int) ([]byte, error)

func (*SystemTools) CheckProcExist

func (s *SystemTools) CheckProcExist(pid int) bool

func (*SystemTools) ContainerFilePath

func (s *SystemTools) ContainerFilePath(pid int, path string) string

func (*SystemTools) ContainerProcFilePath

func (s *SystemTools) ContainerProcFilePath(pid int, path string) string

func (*SystemTools) GetAdvertiseAddr

func (s *SystemTools) GetAdvertiseAddr(addr net.IP) net.IP

func (*SystemTools) GetBindAddr

func (s *SystemTools) GetBindAddr(addr net.IP) (string, *net.IPNet)

func (*SystemTools) GetCgroupNamespacePath

func (s *SystemTools) GetCgroupNamespacePath(pid int) string

func (*SystemTools) GetCgroupVersion

func (s *SystemTools) GetCgroupVersion() int

verify the cgroup's memory controller cgroup v2 is a unified file system, it does not have the memory folder

func (*SystemTools) GetContainerCPUUsage

func (s *SystemTools) GetContainerCPUUsage(cgroupPath string) (uint64, error)

func (*SystemTools) GetContainerCgroupPath

func (s *SystemTools) GetContainerCgroupPath(pid int, subsystem string) (string, error)

func (*SystemTools) GetContainerIDByPID

func (s *SystemTools) GetContainerIDByPID(pid int) (string, bool, error, bool)

Return container ID and if cgroup file exist

func (*SystemTools) GetContainerMemoryLimitUsage

func (s *SystemTools) GetContainerMemoryLimitUsage(cgroupPath string) (uint64, error)

func (*SystemTools) GetContainerMemoryStats

func (s *SystemTools) GetContainerMemoryStats() (*CgroupMemoryStats, error)

func (*SystemTools) GetContainerMemoryUsage

func (s *SystemTools) GetContainerMemoryUsage(cgroupPath string) (uint64, error)

func (*SystemTools) GetExitStatus

func (s *SystemTools) GetExitStatus(err *exec.ExitError) int

func (*SystemTools) GetFileHash

func (s *SystemTools) GetFileHash(pid int, path string) ([]byte, error)

func (*SystemTools) GetFilePath

func (s *SystemTools) GetFilePath(pid int) (string, error)

func (*SystemTools) GetGlobalAddrs

func (s *SystemTools) GetGlobalAddrs(device_only bool) map[string][]net.IPNet

func (*SystemTools) GetHostCPUUsage

func (s *SystemTools) GetHostCPUUsage() (uint64, error)

func (*SystemTools) GetHostRouteIfaceAddr

func (s *SystemTools) GetHostRouteIfaceAddr(addr net.IP) (net.IP, error)

func (*SystemTools) GetHostname

func (s *SystemTools) GetHostname(pid int) string

func (*SystemTools) GetIpcNamespacePath

func (s *SystemTools) GetIpcNamespacePath(pid int) string

func (*SystemTools) GetLocalProcessStatus

func (s *SystemTools) GetLocalProcessStatus(pid int) string

func (*SystemTools) GetMntNamespaceId

func (s *SystemTools) GetMntNamespaceId(pid int) uint64

func (*SystemTools) GetMountNamespacePath

func (s *SystemTools) GetMountNamespacePath(pid int) string

func (*SystemTools) GetNetNamespacePath

func (s *SystemTools) GetNetNamespacePath(pid int) string

func (*SystemTools) GetPidNamespacePath

func (s *SystemTools) GetPidNamespacePath(pid int) string

func (*SystemTools) GetProcRootDir

func (s *SystemTools) GetProcRootDir() string

func (*SystemTools) GetProcessName

func (s *SystemTools) GetProcessName(pid int) (string, int, error)

func (*SystemTools) GetSelfContainerID

func (s *SystemTools) GetSelfContainerID() (string, bool, error)

Reture container ID, if it's container in container and error message

func (*SystemTools) GetSystemInfo

func (s *SystemTools) GetSystemInfo() *sysinfo.SysInfo

func (*SystemTools) GetUserNamespacePath

func (s *SystemTools) GetUserNamespacePath(pid int) string

func (*SystemTools) GetUtsNamespacePath

func (s *SystemTools) GetUtsNamespacePath(pid int) string

func (*SystemTools) IsOpenshift

func (s *SystemTools) IsOpenshift() (bool, error)

func (*SystemTools) IsRunningInContainer

func (s *SystemTools) IsRunningInContainer() bool

func (*SystemTools) KillCommandSubtree

func (s *SystemTools) KillCommandSubtree(pgid int, info string)

func (*SystemTools) LookupAufsContainerLayerPath

func (s *SystemTools) LookupAufsContainerLayerPath(pid int, id string) (string, string, error)

/ Obsolated: the directory names do not correspond to the layer IDs (this has been true since Docker 1.10). / TODO: discover rootFs

func (*SystemTools) MonitorMemoryPressureEvents

func (s *SystemTools) MonitorMemoryPressureEvents(threshold uint64, callback MemoryPressureCallback) error

Linux kernel: mm/vmpressure.c

VMPRESSURE_LOW = 0,
VMPRESSURE_MEDIUM, <== 1, 60%
VMPRESSURE_CRITICAL, <== 2, 95%

These thresholds are used when we account memory pressure through scanned/reclaimed ratio. The current values were chosen empirically. In essence, they are percents: the higher the value, the more number unsuccessful reclaims there were.

func (*SystemTools) NsGetFile

func (s *SystemTools) NsGetFile(filePath string, pid int, binary bool, start, len int) ([]byte, error)

return true if file size over limit

func (*SystemTools) NsRunBinary

func (s *SystemTools) NsRunBinary(pid int, path string) ([]byte, error)

Only can change network namespace

func (*SystemTools) NsRunScript

func (s *SystemTools) NsRunScript(pid int, scripts string) ([]byte, error)

func (*SystemTools) NsRunScriptFile

func (s *SystemTools) NsRunScriptFile(pid int, path string) ([]byte, error)

func (*SystemTools) ParseContainerFilePath

func (s *SystemTools) ParseContainerFilePath(path string) (int, string)

func (*SystemTools) ParseNetNamespacePath

func (s *SystemTools) ParseNetNamespacePath(path string) int

func (*SystemTools) ReCalculateMemoryMetrics

func (s *SystemTools) ReCalculateMemoryMetrics(threshold uint64)

Limit the re-calculate function apart in 5 minutes

func (*SystemTools) ReadAufsContainerLayerPath

func (s *SystemTools) ReadAufsContainerLayerPath(rootPid int, id string) (string, string, error)

func (*SystemTools) ReadCmdLine

func (s *SystemTools) ReadCmdLine(pid int) ([]string, error)

func (*SystemTools) ReadContainerFile

func (s *SystemTools) ReadContainerFile(filePath string, pid, start, length int) ([]byte, error)

func (*SystemTools) ReadMountedBtrfsWorkingPath

func (s *SystemTools) ReadMountedBtrfsWorkingPath(rootPid int, id string) (string, string, error)

func (*SystemTools) ReadMountedUppperLayerPath

func (s *SystemTools) ReadMountedUppperLayerPath(rootPid int, id string) (string, string, error)

func (*SystemTools) RemoveContainerLayerPath

func (s *SystemTools) RemoveContainerLayerPath(id string)

/

func (*SystemTools) RemoveToolProcess

func (s *SystemTools) RemoveToolProcess(pgid int, bKill bool)

func (*SystemTools) ShowToolProcesses

func (s *SystemTools) ShowToolProcesses()

func (*SystemTools) StopToolProcesses

func (s *SystemTools) StopToolProcesses()

type ThrottlingData

type ThrottlingData struct {
	// Number of periods with throttling active
	Periods uint64 `json:"periods,omitempty"`
	// Number of periods when the container hit its throttling limit.
	ThrottledPeriods uint64 `json:"throttled_periods,omitempty"`
	// Aggregate time the container was throttled for in nanoseconds.
	ThrottledTime uint64 `json:"throttled_time,omitempty"`
}

CPU

Directories

Path Synopsis
Package sysinfo is a pure Go library providing Linux OS / kernel / hardware system information.
Package sysinfo is a pure Go library providing Linux OS / kernel / hardware system information.
cpuid
Package cpuid gives Go programs access to CPUID opcode.
Package cpuid gives Go programs access to CPUID opcode.

Jump to

Keyboard shortcuts

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