resource

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

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

Monitor polls CPU and memory usage and provides an Admit gate that blocks dispatch when resources are over threshold.

func New

func New(cpuThresholdPct float64, memThresholdMB uint64) *Monitor

New creates a Monitor and starts polling in the background. Call Stop (via context cancellation) to halt the poller.

func (*Monitor) Admit

func (m *Monitor) Admit(ctx context.Context) error

Admit blocks until resources are below threshold or ctx is cancelled. It waits for the first poll to complete before evaluating. Admit wakes immediately when the poller records a new sample, so it responds within one poll interval rather than busy-polling.

func (*Monitor) Start

func (m *Monitor) Start(ctx context.Context)

Start begins the background polling goroutine; it stops when ctx is cancelled.

func (*Monitor) Stats

func (m *Monitor) Stats() (cpuPct float64, memUsedMB uint64)

Stats returns the most recently sampled CPU% and memory usage in MB.

Jump to

Keyboard shortcuts

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