collector

package
v0.0.0-...-33de0b2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package collector reads domain-free Go runtime, operating-system process, and cgroup memory observations.

Index

Constants

This section is empty.

Variables

View Source
var ErrProcessExited = errors.New("process exited")

ErrProcessExited identifies terminal procfs disappearance separately from a live-process collection failure.

Functions

This section is empty.

Types

type CgroupReader

type CgroupReader struct {
	ProcRoot string
}

CgroupReader resolves a PID's cgroup membership and reads memory accounting from cgroup v2 or v1.

func NewCgroupReader

func NewCgroupReader() *CgroupReader

NewCgroupReader creates a cgroup reader backed by the host procfs mount information.

func (*CgroupReader) Name

func (r *CgroupReader) Name() string

func (*CgroupReader) ReadPID

func (r *CgroupReader) ReadPID(ctx context.Context, pid int) (measurement.Memory, error)

type ComponentReader

type ComponentReader interface {
	Name() string
	ReadPID(context.Context, int) (measurement.Memory, error)
}

ComponentReader reads one subsystem for a resolved PID.

type ProcessReader

type ProcessReader struct {
	ProcRoot string
}

ProcessReader reads Linux procfs status and smaps rollups.

func NewProcessReader

func NewProcessReader() *ProcessReader

NewProcessReader creates a reader for the host procfs.

func (*ProcessReader) Name

func (r *ProcessReader) Name() string

func (*ProcessReader) ReadPID

func (r *ProcessReader) ReadPID(ctx context.Context, pid int) (measurement.Memory, error)

ReadPID reads /proc/<pid>/status and, when available, /proc/<pid>/smaps_rollup.

type ProcessTreeReader

type ProcessTreeReader struct{ ProcRoot string }

ProcessTreeReader sums root and descendant RSS from one procfs snapshot. The sum is approximate because pages shared by processes are counted more than once. ProcessTreeRSSSumBytes deliberately names that limitation.

func NewProcessTreeReader

func NewProcessTreeReader() *ProcessTreeReader

func (*ProcessTreeReader) Name

func (r *ProcessTreeReader) Name() string

func (*ProcessTreeReader) ReadPID

func (r *ProcessTreeReader) ReadPID(ctx context.Context, rootPID int) (measurement.Memory, error)

type Reader

type Reader interface {
	Read(context.Context, Target) (measurement.Memory, error)
}

Reader produces one observation for a target process.

type RuntimeReader

type RuntimeReader struct{}

RuntimeReader observes the Go runtime of the current process. The Go runtime does not expose another process's heap, so external PIDs are marked unavailable rather than approximated.

func NewRuntimeReader

func NewRuntimeReader() *RuntimeReader

NewRuntimeReader creates a Go runtime component reader.

func (*RuntimeReader) Name

func (r *RuntimeReader) Name() string

func (*RuntimeReader) ReadPID

func (r *RuntimeReader) ReadPID(_ context.Context, pid int) (measurement.Memory, error)

ReadPID reads runtime memory when pid is the current process.

type SystemReader

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

SystemReader combines independent runtime, process, and cgroup readers. A failed component becomes a structured field error; useful results from other components are retained.

func NewSystemReader

func NewSystemReader() *SystemReader

NewSystemReader constructs the platform-appropriate production reader.

func NewSystemReaderWithComponents

func NewSystemReaderWithComponents(components ...ComponentReader) *SystemReader

NewSystemReaderWithComponents is primarily useful for deterministic tests and custom platform integrations.

func (*SystemReader) Read

func (r *SystemReader) Read(ctx context.Context, target Target) (measurement.Memory, error)

Read combines all available component observations.

type Target

type Target struct {
	Self bool
	PID  int
}

Target identifies the process to observe. Exactly one of Self or a positive PID must be selected.

func PIDTarget

func PIDTarget(pid int) Target

PIDTarget returns a target for an operating-system process ID.

func SelfTarget

func SelfTarget() Target

SelfTarget returns a target for the current process.

Jump to

Keyboard shortcuts

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