Help us shape the future of Go! Take the 2026 Go Developer Survey

procstats

package
v4.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 15 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartCollector

func StartCollector(collector Collector) io.Closer

StartCollector starts a Collector with a default Config.

func StartCollectorWith

func StartCollectorWith(config Config) io.Closer

StartCollectorWith starts a Collector with the provided Config.

Types

type CPUInfo

type CPUInfo struct {
	User time.Duration // user cpu time used by the process
	Sys  time.Duration // system cpu time used by the process

	// Linux-specific details about the CPU configuration of the process.
	//
	// The values are all zero if they are not known.
	//
	// For more details on what those values represent see:
	//	https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt
	//	https://kernel.googlesource.com/pub/scm/linux/kernel/git/glommer/memcg/+/cpu_stat/Documentation/cgroups/cpu.txt
	Period time.Duration // scheduler period
	Quota  time.Duration // time quota in the scheduler period
	Shares int64         // 1024 scaled value representing the CPU shares
}

CPUInfo holds statistics and configuration details for a process.

type Collector

type Collector interface {
	Collect()
}

Collector is an interface that wraps the Collect() method.

func MultiCollector

func MultiCollector(collectors ...Collector) Collector

MultiCollector coalesces a variadic number of Collectors and returns a single Collector.

type CollectorFunc

type CollectorFunc func()

CollectorFunc is a type alias for func().

func (CollectorFunc) Collect

func (f CollectorFunc) Collect()

Collect calls the underling CollectorFunc func().

type Config

type Config struct {
	Collector       Collector
	CollectInterval time.Duration
}

Config contains a Collector and a time.Duration called CollectInterval.

type DelayInfo

type DelayInfo struct {
	CPUDelay       time.Duration
	BlockIODelay   time.Duration
	SwapInDelay    time.Duration
	FreePagesDelay time.Duration
}

DelayInfo stores delay Durations for various resources.

func CollectDelayInfo

func CollectDelayInfo(pid int) (info DelayInfo, err error)

CollectDelayInfo returns DelayInfo for a pid and an error, if any.

type DelayMetrics

type DelayMetrics struct {
	CPUDelay       time.Duration `metric:"cpu.delay.seconds" type:"counter"`
	BlockIODelay   time.Duration `metric:"blockio.delay.seconds" type:"counter"`
	SwapInDelay    time.Duration `metric:"swapin.delay.seconds" type:"counter"`
	FreePagesDelay time.Duration `metric:"freepages.delay.seconds" type:"counter"`
	// contains filtered or unexported fields
}

DelayMetrics is a metric collector that reports resource delays on processes.

func NewDelayMetrics

func NewDelayMetrics() *DelayMetrics

NewDelayMetrics collects metrics on the current process and reports them to the default stats engine.

func NewDelayMetricsWith

func NewDelayMetricsWith(eng *stats.Engine, pid int) *DelayMetrics

NewDelayMetricsWith collects metrics on the process identified by pid and reports them to eng.

func (*DelayMetrics) Collect

func (d *DelayMetrics) Collect()

Collect satisfies the Collector interface.

type FileInfo

type FileInfo struct {
	Open uint64 // fds opened by the process
	Max  uint64 // max number of fds the process can open
}

FileInfo holds statistics about open and max file handles for a process.

type GoMetrics

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

GoMetrics is a metric collector that reports metrics from the Go runtime.

func NewGoMetrics

func NewGoMetrics() *GoMetrics

NewGoMetrics creates a new collector for the Go runtime that produces metrics on the default stats engine.

func NewGoMetricsWith

func NewGoMetricsWith(eng *stats.Engine) *GoMetrics

NewGoMetricsWith creates a new collector for the Go unrtime that producers metrics on eng.

func (*GoMetrics) Collect

func (g *GoMetrics) Collect()

Collect satisfies the Collector interface.

type MemoryInfo

type MemoryInfo struct {
	Available uint64 // amount of RAM available to the process
	Size      uint64 // total program memory (including virtual mappings)
	Resident  uint64 // resident set size
	Shared    uint64 // shared pages (i.e., backed by a file)
	Text      uint64 // text (code)
	Data      uint64 // data + stack

	MajorPageFaults uint64
	MinorPageFaults uint64
}

MemoryInfo holds statistics and configuration about Memory usage for a process.

type OSUnsupportedError added in v4.7.4

type OSUnsupportedError struct {
	Msg string
}

func (*OSUnsupportedError) Error added in v4.7.4

func (o *OSUnsupportedError) Error() string

type ProcInfo

type ProcInfo struct {
	CPU     CPUInfo
	Memory  MemoryInfo
	Files   FileInfo
	Threads ThreadInfo
}

ProcInfo contains types which hold statistics for various resources.

func CollectProcInfo

func CollectProcInfo(pid int) (ProcInfo, error)

CollectProcInfo returns a ProcInfo and error (if any) for a given PID.

type ProcMetrics

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

ProcMetrics is a metric collector that reports metrics on processes.

func NewProcMetrics

func NewProcMetrics() *ProcMetrics

NewProcMetrics collects metrics on the current process and reports them to the default stats engine.

func NewProcMetricsWith

func NewProcMetricsWith(eng *stats.Engine, pid int) *ProcMetrics

NewProcMetricsWith collects metrics on the process identified by pid and reports them to eng.

func (*ProcMetrics) Collect

func (p *ProcMetrics) Collect()

Collect satisfies the Collector interface.

type ThreadInfo

type ThreadInfo struct {
	Num                        uint64
	VoluntaryContextSwitches   uint64
	InvoluntaryContextSwitches uint64
}

ThreadInfo holds statistics about number of threads and context switches for a process.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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