cpumon

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cpumon provides CPU utilization monitoring with platform-specific implementations.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("cpumon: monitor closed")

ErrClosed is returned by Sample after the monitor has been closed.

Functions

This section is empty.

Types

type CPUSample

type CPUSample = engine.CPUSample

CPUSample is a point-in-time CPU utilization measurement. It is an alias of the public engine.CPUSample so the internal implementations (ProcStat, RuntimeMon) directly satisfy the public engine.CPUMonitor interface and can be passed into adaptive.New from outside the module.

type Monitor

type Monitor = engine.CPUMonitor

Monitor samples CPU utilization. It is an alias of the public engine.CPUMonitor interface, keeping internal/cpumon as the implementation while the type surfaced in public signatures lives in the engine root.

type ProcStat

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

ProcStat reads CPU utilization from /proc/stat.

A single ProcStat is sampled by more than one goroutine in an adaptive setup (the live sampler and the observe collector share one instance), so all mutable state — the shared file handle, the delta accumulators, and the closed flag — is guarded by mu.

func NewProcStat

func NewProcStat() (*ProcStat, error)

NewProcStat creates a /proc/stat-based CPU monitor.

func (*ProcStat) Close

func (p *ProcStat) Close() error

Close releases the file handle. It is idempotent and safe to call concurrently with Sample; once closed, Sample returns ErrClosed instead of touching a file descriptor that may have been reused.

func (*ProcStat) Sample

func (p *ProcStat) Sample() (CPUSample, error)

Sample reads /proc/stat and computes CPU utilization since the last call.

type Synthetic

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

Synthetic is a deterministic CPU monitor for testing.

func NewSynthetic

func NewSynthetic(initial float64) *Synthetic

NewSynthetic creates a synthetic monitor with initial utilization.

func (*Synthetic) Sample

func (s *Synthetic) Sample() (CPUSample, error)

Sample returns the current synthetic utilization.

func (*Synthetic) Set

func (s *Synthetic) Set(util float64)

Set updates the synthetic utilization value.

Jump to

Keyboard shortcuts

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