procutil

package
v0.0.2-0...-4ce78c8 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0, Apache-2.0 Imports: 16 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 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 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 WithPermission

func WithPermission(enabled bool) Option

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

func WithReturnZeroPermStats

func WithReturnZeroPermStats(enabled bool) Option

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

type Probe

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

Probe is a service that fetches process related info on current host

func NewProcessProbe

func NewProcessProbe(options ...Option) *Probe

NewProcessProbe initializes a new Probe object

func (*Probe) Close

func (p *Probe) Close()

Close cleans up everything related to Probe object

func (*Probe) ProcessesByPID

func (p *Probe) ProcessesByPID(now time.Time) (map[int32]*Process, error)

ProcessesByPID returns a map of process info indexed by PID

func (*Probe) StatsForPIDs

func (p *Probe) StatsForPIDs(pids []int32, now time.Time) (map[int32]*Stats, error)

StatsForPIDs returns a map of stats info indexed by PID using the given PIDs

func (*Probe) StatsWithPermByPID

func (p *Probe) StatsWithPermByPID() (map[int32]*StatsWithPerm, error)

StatsWithPermByPID returns the stats that require elevated permission to collect for each process

type Process

type Process struct {
	Pid      int32
	Ppid     int32
	NsPid    int32 // process namespaced PID
	Name     string
	Cwd      string
	Exe      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

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
	CPUTime     *CPUTimesStat
	MemInfo     *MemoryInfoStat
	MemInfoEx   *MemoryInfoExStat
	IOStat      *IOCountersStat
	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

type StatsWithPerm

type StatsWithPerm struct {
	OpenFdCount int32
	IOStat      *IOCountersStat
}

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

Jump to

Keyboard shortcuts

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