Documentation
¶
Index ¶
- Constants
- Variables
- func AddUserToDockerGroup(username string, dockerGID uint32) (bool, error)
- func ApplyShell(username, shell string) error
- func ApplySudo(username string, enable bool) error
- func CreateEnvVars(envVars []string, homeDir string) []string
- func CreateUser(user *models.User) error
- func GetMountUsages() ([]k8shelld.MountUsage, error)
- func GetPIDListeningOnPort(port int) (int, error)
- func GetProcessRunningTime(pid int) (time.Duration, error)
- func GetSignalValue(name string) (syscall.Signal, error)
- func GetStartTimeFromProcStat() (time.Time, error)
- func GetSupplementalGroups(username string) []uint32
- func GetUserLoginShell(username string) (string, error)
- func KillAllProcesses(logger *zerolog.Logger)
- func NewAlpineProvider() *alpineProvider
- func NewStandardProvider() *standardProvider
- func ParseSizeBytes(s string) (uint64, error)
- func UserExists(nameOrUID string) *user.User
- type CPUSample
- type PodmanDetails
- type ProcessInfo
- type ProcessWatcher
- type SystemInfo
- func (s *SystemInfo) Collect(ctx context.Context, refreshTimeSec int) error
- func (s *SystemInfo) GetDockerUsageSnapshot(_ context.Context) (*k8shelld.DockerUsage, error)
- func (s *SystemInfo) GetMountUsageSnapshot() ([]k8shelld.MountUsage, error)
- func (s *SystemInfo) GetPodmanDetailsSnapshot() *PodmanDetails
- func (s *SystemInfo) GetSystemInfoHistory(q k8shelld.SystemInfoHistoryQuery) (*k8shelld.SystemInfoHistory, error)
- func (s *SystemInfo) GetSystemUsageSnapshot() (*k8shelld.SystemUsage, error)
- type SystemStats
Constants ¶
const ( // HistoryRetention is how long historical system/mount/docker usage // samples are kept in memory before aging out. HistoryRetention = 24 * time.Hour // MaxHistoryPoints caps the number of points returned for a single // series in one SystemInfoHistory response; a finer step than this // would allow is coarsened to respect it. MaxHistoryPoints = 720 // DefaultHistoryRange is the window used when a request supplies // neither range nor a from/to pair. DefaultHistoryRange = 1 * time.Hour )
const MaxCPUSamples = 100 // Maximum number of CPU samples to keep in history
Variables ¶
var SignalMap = map[string]syscall.Signal{ "ABRT": syscall.SIGABRT, "ALRM": syscall.SIGALRM, "FPE": syscall.SIGFPE, "HUP": syscall.SIGHUP, "ILL": syscall.SIGILL, "INT": syscall.SIGINT, "KILL": syscall.SIGKILL, "PIPE": syscall.SIGPIPE, "QUIT": syscall.SIGQUIT, "SEGV": syscall.SIGSEGV, "TERM": syscall.SIGTERM, "USR1": syscall.SIGUSR1, "USR2": syscall.SIGUSR2, "CHLD": syscall.SIGCHLD, "CONT": syscall.SIGCONT, "STOP": syscall.SIGSTOP, "TSTP": syscall.SIGTSTP, "TTIN": syscall.SIGTTIN, "TTOU": syscall.SIGTTOU, "URG": syscall.SIGURG, "XCPU": syscall.SIGXCPU, "XFSZ": syscall.SIGXFSZ, }
Map of signal names to their corresponding syscall.Signal values
Functions ¶
func AddUserToDockerGroup ¶
AddUserToDockerGroup adds the given user to the group identified by dockerGID. If no group with that GID exists in /etc/group, a new group named "docker" is created first. This does not require the Docker socket to be present.
func ApplyShell ¶
ApplyShell updates the login shell for the given user in /etc/passwd. It performs an atomic write so the file is never left in a partial state.
func ApplySudo ¶
ApplySudo enables or revokes passwordless sudo for the given user. It is safe to call this function at any time, including when the sudo state has not changed.
func CreateEnvVars ¶
CreateEnvVars creates new environment variables with the provided environment variables and a home directory. It includes all existing environment variables and ensures that duplicate keys are not added and that the HOME variable is set correctly.
func CreateUser ¶
CreateUser creates the user in the system.
func GetMountUsages ¶
func GetMountUsages() ([]k8shelld.MountUsage, error)
func GetPIDListeningOnPort ¶
GetPIDListeningOnPort tries to find a PID that is listening on the given TCP port.
func GetProcessRunningTime ¶
GetProcessRunningTime returns how long the given PID has been running as a time.Duration.
func GetSignalValue ¶
Function to convert signal name to syscall.Signal value
func GetStartTimeFromProcStat ¶
getStartTimeFromProcStat retrieves the start time of the process from /proc/1/stat
func GetSupplementalGroups ¶
func GetUserLoginShell ¶
GetUserLoginShell returns the login shell for the given user.
func KillAllProcesses ¶
func NewAlpineProvider ¶
func NewAlpineProvider() *alpineProvider
func NewStandardProvider ¶
func NewStandardProvider() *standardProvider
func ParseSizeBytes ¶
parseSizeBytes parses Kubernetes-style quantities (compatible with resource.Quantity), e.g.: - Binary SI: Ki, Mi, Gi, Ti, Pi, Ei (base 1024) e.g. "10Gi", "1.5Gi" - Decimal SI: n, u, m, k, M, G, T, P, E (base 10) e.g. "500M", "1G", "250m" - Scientific notation is accepted e.g. "1e3", "1.2e6"
func UserExists ¶
userExists checks if a user with the given name or UID exists.
Types ¶
type PodmanDetails ¶
type PodmanDetails struct {
PodmanVersion string `json:"podmanVersion"` // e.g. "5.8.1"
GraphDriver string `json:"graphDriver"` // e.g. "overlay"
RunRoot string `json:"runRoot"` // e.g. "/tmp/storage-run-1000/containers"
ContainersTotal int `json:"containersTotal"`
ContainersRunning int `json:"containersRunning"`
ContainersPaused int `json:"containersPaused"`
ContainersStopped int `json:"containersStopped"`
}
PodmanDetails carries Podman-specific metadata that has no equivalent in the Docker-compat DockerUsage proto. It is populated from /libpod/info.
func GetDockerUsage ¶
func GetDockerUsage(ctx context.Context) (*k8shelld.DockerUsage, *PodmanDetails, error)
type ProcessInfo ¶
type ProcessInfo struct {
// contains filtered or unexported fields
}
type ProcessWatcher ¶
type ProcessWatcher struct {
// contains filtered or unexported fields
}
func NewProcessWatcher ¶
func NewProcessWatcher(terminateOrphans bool, reapZombies bool, checkInterval int, excludePatterns []string) *ProcessWatcher
func (*ProcessWatcher) AddPIDIgnoreTerminate ¶
func (p *ProcessWatcher) AddPIDIgnoreTerminate(pid int)
func (*ProcessWatcher) LockForCreation ¶
func (p *ProcessWatcher) LockForCreation() func()
LockForCreation must be called before starting a child process and the returned unlock function called immediately after AddPIDIgnoreTerminate. This prevents terminateOrphans from seeing a newly-started process before its PID has been added to the ignore list.
func (*ProcessWatcher) Run ¶
func (p *ProcessWatcher) Run(ctx context.Context)
type SystemInfo ¶
type SystemInfo struct {
CollectedAt time.Time // Time of collection
CPUUsageUsec int64 // CPU usage in microseconds
CPUUsageMillicores float64 // CPU usage in mCPU
MemoryUsageMiB float64 // Memory usage in MiB
CPULimitMillicores float64 // CPU limit in mCPU (if set)
MemLimitMiB float64 // Memory limit in MiB (if set)
CPUUsageSeconds float64 // CPU usage in seconds
CPUAvg1Min float64 // CPU usage average over 1 minute
CPUAvg5Min float64 // CPU usage average over 5 minutes
CPUAvg15Min float64 // CPU usage average over 15 minutes
// contains filtered or unexported fields
}
Usage struct to hold CPU & Memory metrics The metrics are collected from cgroups v2 files
func NewSystemInfo ¶
func NewSystemInfo(config *config.Config, blueprint *commonmodels.Blueprint) *SystemInfo
func (*SystemInfo) Collect ¶
func (s *SystemInfo) Collect(ctx context.Context, refreshTimeSec int) error
func (*SystemInfo) GetDockerUsageSnapshot ¶
func (s *SystemInfo) GetDockerUsageSnapshot(_ context.Context) (*k8shelld.DockerUsage, error)
GetDockerUsageSnapshot returns the cached docker usage. Refreshed in the background by Collect.
func (*SystemInfo) GetMountUsageSnapshot ¶
func (s *SystemInfo) GetMountUsageSnapshot() ([]k8shelld.MountUsage, error)
GetMountUsageSnapshot returns the cached mount usage. Refreshed in the background by Collect.
func (*SystemInfo) GetPodmanDetailsSnapshot ¶
func (s *SystemInfo) GetPodmanDetailsSnapshot() *PodmanDetails
GetPodmanDetailsSnapshot returns the cached extra Podman details. Refreshed in the background by Collect.
func (*SystemInfo) GetSystemInfoHistory ¶ added in v0.16.0
func (s *SystemInfo) GetSystemInfoHistory(q k8shelld.SystemInfoHistoryQuery) (*k8shelld.SystemInfoHistory, error)
GetSystemInfoHistory resolves a SystemInfoHistory query against the recorded ring buffer and returns the downsampled series. The returned From/To/Step reflect what was actually used after clamping/coarsening.
func (*SystemInfo) GetSystemUsageSnapshot ¶
func (s *SystemInfo) GetSystemUsageSnapshot() (*k8shelld.SystemUsage, error)
GetSystemUsageSnapshot returns a snapshot of system metrics.
type SystemStats ¶
SystemStats holds the history of CPU usage samples
func (*SystemStats) AddSample ¶
func (s *SystemStats) AddSample(sample CPUSample)
NewSystemStats initializes a new SystemStats instance
func (*SystemStats) GetAverage ¶
func (s *SystemStats) GetAverage(duration time.Duration) float64
GetAverage returns the average CPU usage in millicores over the specified duration