monitor

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct {
	Memory     int64   `json:"memory"`     // Memory usage in bytes
	CPU        float64 `json:"cpu"`        // CPU usage percentage
	Goroutines int32   `json:"goroutines"` // Number of goroutines
	HeapAlloc  uint64  `json:"heap_alloc"` // Heap allocation in bytes
	HeapSys    uint64  `json:"heap_sys"`   // Heap system memory in bytes
	HeapIdle   uint64  `json:"heap_idle"`  // Heap idle memory in bytes
	GCCount    uint32  `json:"gc_count"`   // Number of completed GC cycles
	GCPause    uint64  `json:"gc_pause"`   // Total GC pause in nanoseconds
}

Metrics tracks runtime metrics

type RuntimeStats

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

RuntimeStats monitors runtime metrics like memory, CPU, goroutines and GC

func NewRuntimeStats

func NewRuntimeStats(ctx context.Context, config *RuntimeStatsConfig) (*RuntimeStats, error)

NewRuntimeStats creates a new runtime monitor

Usage:

ctx := context.Background()
config := DefaultConfig()
config.MaxMemory = 2 * 1024 * 1024 * 1024  // 2GB

monitor := NewRuntimeStats(ctx, config)
monitor.Start()
defer monitor.Stop()

// Get current usage
usage := monitor.GetMetrics()

func (*RuntimeStats) CheckThresholds

func (m *RuntimeStats) CheckThresholds() []error

CheckThresholds checks if current usage exceeds thresholds

func (*RuntimeStats) GetConfig

func (m *RuntimeStats) GetConfig() *RuntimeStatsConfig

GetConfig returns current configuration

func (*RuntimeStats) GetMetrics

func (m *RuntimeStats) GetMetrics() Metrics

GetMetrics gets current runtime metrics

func (*RuntimeStats) GetPeakUsage

func (m *RuntimeStats) GetPeakUsage() Metrics

GetPeakUsage gets peak runtime usage

func (*RuntimeStats) IsEnabled

func (m *RuntimeStats) IsEnabled() bool

IsEnabled returns if monitoring is enabled

func (*RuntimeStats) Reset

func (m *RuntimeStats) Reset()

Reset resets peak usage metrics

func (*RuntimeStats) Start

func (m *RuntimeStats) Start()

Start starts runtime monitoring

func (*RuntimeStats) Stop

func (m *RuntimeStats) Stop()

Stop stops runtime monitoring

type RuntimeStatsConfig

type RuntimeStatsConfig struct {
	// Monitor
	MaxMemory     int64         `json:"max_memory"`     // Max memory usage in bytes
	MaxCPU        float64       `json:"max_cpu"`        // Max CPU usage percentage
	MaxGoroutines int32         `json:"max_goroutines"` // Max number of goroutines
	Interval      time.Duration `json:"interval"`       // Monitoring interval
	EnableCPU     bool          `json:"enable_cpu"`     // Enable CPU monitoring
	EnableMemory  bool          `json:"enable_memory"`  // Enable memory monitoring
	EnableGC      bool          `json:"enable_gc"`      // Enable GC stats monitoring
}

RuntimeStatsConfig contains configuration for runtime stats monitor

func DefaultConfig

func DefaultConfig() *RuntimeStatsConfig

DefaultConfig returns default configuration

func (*RuntimeStatsConfig) Validate

func (c *RuntimeStatsConfig) Validate() error

Jump to

Keyboard shortcuts

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