Documentation ¶
Overview ¶
Package process provides functionality used to evaluate processes for problematic states.
Index ¶
- Constants
- Variables
- func GetProcDirs(path string) ([]string, error)
- func KnownCriticalProcessStates() []string
- func KnownProblemProcessStates() []string
- func KnownWarningProcessStates() []string
- func SupportedProcessStates() []string
- type Process
- type Processes
- func (ps Processes) Count() int
- func (ps Processes) Exclude(exclude ...Process) Processes
- func (ps Processes) ExcludeMyPID() Processes
- func (ps Processes) HasCriticalState() bool
- func (ps Processes) HasWarningState() bool
- func (ps Processes) IsOKState() bool
- func (ps Processes) MyProcess() Process
- func (ps Processes) NumCriticalState() int
- func (ps Processes) NumOKState() int
- func (ps Processes) NumWarningState() int
- func (ps Processes) ParentProcess(p Process) (Process, error)
- func (ps Processes) ServiceState() nagios.ServiceState
- func (ps Processes) State(state string) Processes
- func (ps Processes) StateCount(state string) int
- func (ps Processes) StateDead() Processes
- func (ps Processes) StateDeadCount() int
- func (ps Processes) StateDiskSleep() Processes
- func (ps Processes) StateDiskSleepCount() int
- func (ps Processes) StateIdle() Processes
- func (ps Processes) StateIdleCount() int
- func (ps Processes) StateParked() Processes
- func (ps Processes) StateParkedCount() int
- func (ps Processes) StateRunning() Processes
- func (ps Processes) StateRunningCount() int
- func (ps Processes) StateSleeping() Processes
- func (ps Processes) StateSleepingCount() int
- func (ps Processes) StateStopped() Processes
- func (ps Processes) StateStoppedCount() int
- func (ps Processes) StateTracingStop() Processes
- func (ps Processes) StateTracingStopCount() int
- func (ps Processes) StateWakeKill() Processes
- func (ps Processes) StateWakeKillCount() int
- func (ps Processes) StateWaking() Processes
- func (ps Processes) StateWakingCount() int
- func (ps Processes) StateZombie() Processes
- func (ps Processes) StateZombieCount() int
- func (ps Processes) States(states []string) Processes
- func (ps Processes) SummaryList() []string
- func (ps Processes) SummaryOneLine() string
- type Properties
Constants ¶
const ( // ProcRootDir is the default mount point for the proc virtual filesystem. ProcRootDir string = "/proc" // ProcStatusFilename is the name of the human-readable process status // information present for each process directory in the proc filesystem. ProcStatusFilename string = "status" // ProcDirRegex is the regex pattern used to match process directory names // within the proc virtual filesystem. ProcDirRegex string = "^[0-9]+$" )
const ( ProcessNameField string = "name" ProcessStateField string = "state" ProcessPidField string = "pid" ProcessPPidField string = "ppid" ProcessThreadsField string = "threads" ProcessVMSwapField string = "vmswap" )
Process status field names.
const ( KernelAnyProcessStateRunning string = "R (running)" KernelAnyProcessStateSleeping string = "S (sleeping)" KernelAnyProcessStateDiskSleep string = "D (disk sleep)" KernelAnyProcessStateStopped string = "T (stopped)" KernelAnyProcessStateZombie string = "Z (zombie)" KernelAnyProcessStateDead string = "X (dead)" )
Process state values observed for 2.6.32, 3.10, 4.18 & 5.14 kernels and presumed to be stable enough to be used by future kernels.
const ( KernelLegacyProcessStateTracingStop string = "T (tracing stop)" // kernel 2.6.32 KernelLegacyProcessStateDead string = "x (dead)" // kernel 3.10 KernelLegacyProcessStateWakeKill string = "K (wakekill)" // kernel 3.10 KernelLegacyProcessStateWaking string = "W (waking)" // kernel 3.10 )
Process state values observed for legacy kernels that are not present on current/modern kernel versions.
const ( KernelCurrentProcessStateTracingStop string = "t (tracing stop)" // kernel 3.10, 4.18, 5.14 KernelCurrentProcessStateIdle string = "I (idle)" // kernel 4.18, 5.14 KernelCurrentProcessStateParked string = "P (parked)" // kernel 3.10, 4.18, 5.14 )
Process state values observed for newer kernel versions and presumed to be stable enough to be used by future kernels.
Variables ¶
var ( // ErrProblemProcessesFound indicates that one or more "problematic" // processes were found (e.g., uninterruptible disk sleep) which warrant // surfacing the issue. ErrProblemProcessesFound = errors.New("problematic processes found") // ErrInvalidProcStatusLineFormat indicates that a status file within the // /proc filesystem has an invalid key/value format. ErrInvalidProcStatusLineFormat = errors.New("invalid format for proc status line") // ErrInvalidProcStatusLineValue indicates that a status file within the // /proc filesystem has an invalid value (wrong type) for a process // property. ErrInvalidProcStatusLineValue = errors.New("invalid value for proc status line") // ErrMissingProcessPropertiesIndexEntry indicates that a requested // process property entry is missing from the index. ErrMissingProcessPropertiesIndexEntry = errors.New("entry missing from process properties index") // ErrInvalidProcessPropertiesIndexCount indicates that a // ProcessProperties index (map) is missing the minimum required entries // used to populate specific fields of a Process. ErrInvalidProcessPropertiesIndexCount = errors.New("minimum entries not present in process properties index") // ErrMissingProcessEntry indicates that an expected process was not found // in a given collection. ErrMissingProcessEntry = errors.New("process missing from collection") )
Functions ¶
func GetProcDirs ¶
GetProcDirs evaluates the given base path (usually "/proc") for known process directories within the proc filesystem and returns an unqualified list of all valid matches.
func KnownCriticalProcessStates ¶
func KnownCriticalProcessStates() []string
KnownCriticalProcessStates returns a list of the process states known to be problematic. These states are considered CRITICAL.
func KnownProblemProcessStates ¶
func KnownProblemProcessStates() []string
KnownProblemProcessStates provides a list of the process states known to be problematic.
func KnownWarningProcessStates ¶
func KnownWarningProcessStates() []string
KnownWarningProcessStates provides a list of the process states known to be problematic and warrant a WARNING, but not so severe to be considered CRITICAL.
func SupportedProcessStates ¶
func SupportedProcessStates() []string
SupportedProcessStates provides a list of the process states supported by this package. Not all process states are supported by all kernel versions.
Types ¶
type Process ¶
type Process struct { Name string // State is the current state of the process. // // Valid values for a 2.6.32 (RHEL 6) kernel: // // "R (running)" // "S (sleeping)" // "D (disk sleep)" // "T (stopped)" // "T (tracing stop)" // "Z (zombie)" // "X (dead)" // // Valid values for a 3.10 (RHEL 7) kernel: // // "R (running)" // "S (sleeping)" // "D (disk sleep)" // "T (stopped)" // "t (tracing stop)" // "Z (zombie)" // "X (dead)" // "x (dead)" // "K (wakekill)" // "W (waking)" // "P (parked)" // // // Valid values for a 4.18 (RHEL 8) and 5.14 (RHEL 9) kernel: // // "R (running)" // "S (sleeping)" // "D (disk sleep)" // "T (stopped)" // "t (tracing stop)" // "X (dead)" // "Z (zombie)" // "P (parked)" // "I (idle)" // // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/proc/array.c?h=v2.6.32#n136 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/proc/array.c?h=v3.10#n135 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/proc/array.c?h=v4.18#n130 // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/proc/array.c?h=v5.14#n130 State string Pid int PPid int Threads int VMSwap string AllProperties Properties }
Process provides select type-safe values related to a running process (per /proc) and a map of property/values in string format.
https://man7.org/linux/man-pages/man5/proc.5.html https://linux.die.net/man/5/proc
func ParseProcStatusFile ¶
ParseProcStatusFile parses a given /proc/[pid]/status file and returns a Process value representing the status of a process.
func (Process) IsCriticalState ¶
IsCriticalState indicates whether the state matches known CRITICAL severity process states.
func (Process) IsOKState ¶
IsOKState indicates whether the process state is not in a list of known problematic process states.
func (Process) IsWarningState ¶
IsWarningState indicates whether the state matches known WARNING severity process states.
type Processes ¶
type Processes []Process
Processes is a collection of Process values.
func FromProcDirs ¶
FromProcDirs evaluates the status file within a given list of /proc/[pid] directories and returns either a collection of Process values or an error if one occurs.
func (Processes) Exclude ¶
Exclude returns Process values from the collection which are not in the specified set. If the specified set is empty all Process values in the collection are returned. If the
func (Processes) ExcludeMyPID ¶ added in v0.1.1
ExcludeMyPID returns Process values from the collection which do not match the current process ID value of the tool executing this code.
func (Processes) HasCriticalState ¶
HasCriticalState indicates whether any items in the collection were evaluated to a CRITICAL state.
func (Processes) HasWarningState ¶
HasWarningState indicates whether any items in the collection were evaluated to a WARNING state.
func (Processes) IsOKState ¶
IsOKState indicates whether all items in the collection were evaluated to an OK state.
func (Processes) MyProcess ¶ added in v0.1.1
MyProcess returns the Process value from the collection which matches the current process ID value of the tool executing this code. A zero value Process is returned if a match is not found for the current process ID value.
func (Processes) NumCriticalState ¶
NumCriticalState indicates how many items in the collection were evaluated to a CRITICAL state.
func (Processes) NumOKState ¶
NumOKState indicates how many items in the collection were evaluated to an OK state.
func (Processes) NumWarningState ¶
NumWarningState indicates how many items in the collection were evaluated to a WARNING state.
func (Processes) ParentProcess ¶
ParentProcess returns the parent Process for the specified Process value from the collection or an error if one occurs.
func (Processes) ServiceState ¶
func (ps Processes) ServiceState() nagios.ServiceState
ServiceState returns the appropriate Service Check Status label and exit code for the collection's evaluation results.
func (Processes) State ¶
State returns each Process from the collection that are in the specified state. The caller is encouraged to specify state values using applicable state value constants for best results. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateCount ¶
StateCount is a helper method used to indicate how many processes in the collection are in the specified state. The caller is encouraged to specify state values using applicable state value constants for best results.
func (Processes) StateDead ¶
StateDead returns each Process from the collection currently in a dead state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateDeadCount ¶
StateDeadCount returns the number of processes from the collection currently in a dead state.
func (Processes) StateDiskSleep ¶
StateDiskSleep returns each Process from the collection currently in a disk sleep state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateDiskSleepCount ¶
StateDiskSleepCount returns the number of processes from the collection currently in a disk sleep state.
func (Processes) StateIdle ¶
StateIdle returns each Process from the collection currently in an idle state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateIdleCount ¶
StateIdleCount returns the number of processes from the collection currently in a idle state.
func (Processes) StateParked ¶
StateParked returns each Process from the collection currently in a parked state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateParkedCount ¶
StateParkedCount returns the number of processes from the collection currently in a parked state.
func (Processes) StateRunning ¶
StateRunning returns each Process from the collection currently in a running state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateRunningCount ¶
StateRunningCount returns the number of processes from the collection currently in a running state.
func (Processes) StateSleeping ¶
StateSleeping returns each Process from the collection currently in a sleeping state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateSleepingCount ¶
StateSleepingCount returns the number of processes from the collection currently in a sleeping state.
func (Processes) StateStopped ¶
StateStopped returns each Process from the collection currently in a stopped state. Processes in a "tracing stop" state are not evaluated.
The returned collection may be empty if no processes are in the requested state.
func (Processes) StateStoppedCount ¶
StateStoppedCount returns the number of processes from the collection currently in a stopped state.
func (Processes) StateTracingStop ¶
StateTracingStop returns each Process from the collection currently in a tracing stop state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateTracingStopCount ¶
StateTracingStopCount returns the number of processes from the collection currently in a tracing stop state.
func (Processes) StateWakeKill ¶
StateWakeKill returns each Process from the collection currently in a wakekill state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateWakeKillCount ¶
StateWakeKillCount returns the number of processes from the collection currently in a wakekill state.
func (Processes) StateWaking ¶
StateWaking returns each Process from the collection currently in a waking state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateWakingCount ¶
StateWakingCount returns the number of processes from the collection currently in a waking state.
func (Processes) StateZombie ¶
StateZombie returns each Process from the collection currently in a zombie state. The returned collection may be empty if no processes are in the requested state.
func (Processes) StateZombieCount ¶
StateZombieCount returns the number of processes from the collection currently in a zombie state.
func (Processes) States ¶
States returns each Process from the collection that are in the specified states. The caller is encouraged to specify state values using applicable state value constants for best results. The returned collection is empty if no processes are in the requested states.
func (Processes) SummaryList ¶
SummaryList returns a slice of process summary items.
func (Processes) SummaryOneLine ¶
SummaryOneLine returns a one line summary of all processes.
type Properties ¶
Properties is a collection of key/value string pairs representing the various properties for a running process. Each key is lowercased with the original value retained as-is.