statscollector

package
v1.45.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector collects and stores metrics history for multiple processes.

func NewCollector

func NewCollector(maxSamples int) *Collector

NewCollector creates a new Collector with a sample retention limit.

func (*Collector) AddSample

func (sc *Collector) AddSample(stats ProcessStats)

AddSample records new sample.

func (*Collector) AverageCPUUsage

func (sc *Collector) AverageCPUUsage(since time.Duration) float64

AverageCPUUsage computes average CPU usage as a fraction of one core.

func (*Collector) AverageMemoryUsage

func (sc *Collector) AverageMemoryUsage(since time.Duration) uint64

AverageMemoryUsage returns the average stats over the given time window.

func (*Collector) GetSamples

func (sc *Collector) GetSamples(since time.Duration) []Sample

GetSamples returns all samples within the given time window.

type ProcessStats

type ProcessStats struct {
	CPUTimeSec float64 `json:"cpu_time_sec"`
	MemoryRSS  uint64  `json:"memory_rss_bytes"`
}

ProcessStats stores basic stats.

type Sample

type Sample struct {
	Timestamp  time.Time
	CPUTimeSec float64
	MemoryRSS  uint64
}

Sample represents a single timestamped metrics snapshot.

Jump to

Keyboard shortcuts

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