procutil

package
v0.0.0-...-41dbc07 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WorldReadable represents file permission that's world readable
	WorldReadable os.FileMode = 4
	// DefaultClockTicks is the default number of clock ticks per second
	// C.sysconf(C._SC_CLK_TCK)
	DefaultClockTicks = float64(100)
)

Variables

View Source
var (
	// PageSize is the system's memory page size
	PageSize = uint64(os.Getpagesize())
)

Functions

func ConvertAllFilledProcesses

func ConvertAllFilledProcesses(processes map[int32]*process.FilledProcess) map[int32]*Process

ConvertAllFilledProcesses takes a group of FilledProcess objects and convert them into Process

func ConvertAllFilledProcessesToStats

func ConvertAllFilledProcessesToStats(processes map[int32]*process.FilledProcess) map[int32]*Stats

ConvertAllFilledProcessesToStats takes a group of FilledProcess objects and convert them into Stats

func PidExists

func PidExists(pid int) bool

PidExists returns true if the pid is still alive

Types

type CPUPercentStat

type CPUPercentStat struct {
	UserPct   float64
	SystemPct float64
}

CPUPercentStat holds CPU stat metrics of a process as CPU usage percent

type CPUTimesStat

type CPUTimesStat struct {
	User      float64
	System    float64
	Idle      float64
	Nice      float64
	Iowait    float64
	Irq       float64
	Softirq   float64
	Steal     float64
	Guest     float64
	GuestNice float64
	Stolen    float64
	Timestamp int64
}

CPUTimesStat holds CPU stat metrics of a process

func ConvertFromCPUStat

func ConvertFromCPUStat(s cpu.TimesStat) *CPUTimesStat

ConvertFromCPUStat converts gopsutil TimesStat object to CPUTimesStat in procutil

func (*CPUTimesStat) Total

func (c *CPUTimesStat) Total() float64

Total returns the total number of seconds in a CPUTimesStat

type DataScrubber

type DataScrubber struct {
	Enabled           bool
	StripAllArguments bool
	SensitivePatterns []DataScrubberPattern
	// contains filtered or unexported fields
}

DataScrubber allows the agent to disallow-list cmdline arguments that match a list of predefined and custom words

func NewDefaultDataScrubber

func NewDefaultDataScrubber() *DataScrubber

NewDefaultDataScrubber creates a DataScrubber with the default behavior: enabled and matching the default sensitive words

func (*DataScrubber) AddCustomSensitiveWords

func (ds *DataScrubber) AddCustomSensitiveWords(words []string)

AddCustomSensitiveWords adds custom sensitive words on the DataScrubber object

func (*DataScrubber) IncrementCacheAge

func (ds *DataScrubber) IncrementCacheAge()

IncrementCacheAge increments one cycle of cache memory age. If it reaches cacheMaxCycles, the cache is restarted

func (*DataScrubber) ScrubCommand

func (ds *DataScrubber) ScrubCommand(cmdline []string) ([]string, bool)

ScrubCommand hides the argument value for any key which matches a "sensitive word" pattern. It returns the updated cmdline, as well as a boolean representing whether it was scrubbed

func (*DataScrubber) ScrubProcessCommand

func (ds *DataScrubber) ScrubProcessCommand(p *Process) []string

ScrubProcessCommand uses a cache memory to avoid scrubbing already known process' cmdlines

type DataScrubberPattern

type DataScrubberPattern struct {
	FastCheck string
	Re        *regexp.Regexp
}

func CompileStringsToRegex

func CompileStringsToRegex(words []string) []DataScrubberPattern

CompileStringsToRegex compile each word in the slice into a regex pattern to match against the cmdline arguments The word must contain only word characters ([a-zA-z0-9_]) or wildcards *

type IOCountersRateStat

type IOCountersRateStat struct {
	ReadRate       float64
	WriteRate      float64
	ReadBytesRate  float64
	WriteBytesRate float64
}

IOCountersRateStat holds IO metrics for a process represented as rates (/sec)

type IOCountersStat

type IOCountersStat struct {
	ReadCount  int64
	WriteCount int64
	ReadBytes  int64
	WriteBytes int64
}

IOCountersStat holds IO metrics for a process

func ConvertFromIOStats

func ConvertFromIOStats(s *process.IOCountersStat) *IOCountersStat

ConvertFromIOStats converts gopsutil IOCountersStat object to IOCounterStat in procutil

func (*IOCountersStat) IsZeroValue

func (i *IOCountersStat) IsZeroValue() bool

IsZeroValue checks whether all fields are 0 in value for IOCountersStat

type MemoryInfoExStat

type MemoryInfoExStat struct {
	RSS    uint64 // bytes
	VMS    uint64 // bytes
	Shared uint64 // bytes
	Text   uint64 // bytes
	Lib    uint64 // bytes
	Data   uint64 // bytes
	Dirty  uint64 // bytes
}

MemoryInfoExStat holds all memory metrics for a process

func ConvertFromMemInfoEx

func ConvertFromMemInfoEx(s *process.MemoryInfoExStat) *MemoryInfoExStat

ConvertFromMemInfoEx converts gopsutil MemoryInfoExStat object to MemoryInfoExStat in procutil

type MemoryInfoStat

type MemoryInfoStat struct {
	RSS  uint64 // bytes
	VMS  uint64 // bytes
	Swap uint64 // bytes
}

MemoryInfoStat holds commonly used memory metrics for a process

func ConvertFromMemInfo

func ConvertFromMemInfo(s *process.MemoryInfoStat) *MemoryInfoStat

ConvertFromMemInfo converts gopsutil MemoryInfoStat object to MemoryInfoStat in procutil

type NumCtxSwitchesStat

type NumCtxSwitchesStat struct {
	Voluntary   int64
	Involuntary int64
}

NumCtxSwitchesStat holds context switch metrics for a process

func ConvertFromCtxSwitches

func ConvertFromCtxSwitches(s *process.NumCtxSwitchesStat) *NumCtxSwitchesStat

ConvertFromCtxSwitches converts gopsutil NumCtxSwitchesStat object to NumCtxSwitchesStat in procutil

type Option

type Option func(p Probe)

Option is config options callback for system-probe

func WithBootTimeRefreshInterval

func WithBootTimeRefreshInterval(bootTimeRefreshInterval time.Duration) Option

WithBootTimeRefreshInterval configures the boot time refresh interval

func WithIgnoreZombieProcesses

func WithIgnoreZombieProcesses(ignoreZombieProcesses bool) Option

WithIgnoreZombieProcesses configures if process collection should ignore zombie processes or not

func WithPermission

func WithPermission(elevatedPermissions bool) Option

WithPermission configures if process collection should fetch fields that require elevated permission or not

func WithProcFSRoot

func WithProcFSRoot(path string) Option

WithProcFSRoot confiugres the procfs directory that the probe reads from

func WithReturnZeroPermStats

func WithReturnZeroPermStats(enabled bool) Option

WithReturnZeroPermStats configures whether StatsWithPermByPID() returns StatsWithPerm that has zero values on all fields

type Probe

type Probe interface {
	Close()
	StatsForPIDs(pids []int32, now time.Time) (map[int32]*Stats, error)
	ProcessesByPID(now time.Time, collectStats bool) (map[int32]*Process, error)
	StatsWithPermByPID(pids []int32) (map[int32]*StatsWithPerm, error)
}

Probe fetches process related info on current host

func NewProcessProbe

func NewProcessProbe(options ...Option) Probe

NewProcessProbe initializes a new Probe object

type Process

type Process struct {
	Pid      int32
	Ppid     int32
	NsPid    int32 // process namespaced PID
	Name     string
	Cwd      string
	Exe      string
	Comm     string
	Cmdline  []string
	Username string // (Windows only)
	Uids     []int32
	Gids     []int32

	Stats *Stats
}

Process holds all relevant metadata and metrics for a process

func ConvertFromFilledProcess

func ConvertFromFilledProcess(p *process.FilledProcess) *Process

ConvertFromFilledProcess takes a FilledProcess object and convert it into Process

func (*Process) DeepCopy

func (p *Process) DeepCopy() *Process

DeepCopy creates a deep copy of Process

func (*Process) GetCmdline

func (p *Process) GetCmdline() []string

func (*Process) GetCommand

func (p *Process) GetCommand() string

func (*Process) GetPid

func (p *Process) GetPid() int32

type Stats

type Stats struct {
	CreateTime int64
	// Status returns the process status.
	// Return value could be one of these.
	// R: Running S: Sleep T: Stop I: Idle
	// Z: Zombie W: Wait L: Lock
	// The character is the same within all supported platforms.
	Status      string
	Nice        int32
	OpenFdCount int32
	NumThreads  int32
	CPUPercent  *CPUPercentStat
	CPUTime     *CPUTimesStat
	MemInfo     *MemoryInfoStat
	MemInfoEx   *MemoryInfoExStat
	IOStat      *IOCountersStat
	IORateStat  *IOCountersRateStat
	CtxSwitches *NumCtxSwitchesStat
}

Stats holds all relevant stats metrics of a process

func ConvertFilledProcessesToStats

func ConvertFilledProcessesToStats(p *process.FilledProcess) *Stats

ConvertFilledProcessesToStats takes a group of FilledProcess objects and convert them into Stats

func (*Stats) DeepCopy

func (s *Stats) DeepCopy() *Stats

DeepCopy creates a deep copy of Stats

type StatsWithPerm

type StatsWithPerm struct {
	OpenFdCount int32
	IOStat      *IOCountersStat
}

StatsWithPerm is a collection of stats that require elevated permission to collect in linux

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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