Documentation
¶
Index ¶
- type Metrics
- type RuntimeStats
- func (m *RuntimeStats) CheckThresholds() []error
- func (m *RuntimeStats) GetConfig() *RuntimeStatsConfig
- func (m *RuntimeStats) GetMetrics() Metrics
- func (m *RuntimeStats) GetPeakUsage() Metrics
- func (m *RuntimeStats) IsEnabled() bool
- func (m *RuntimeStats) Reset()
- func (m *RuntimeStats) Start()
- func (m *RuntimeStats) Stop()
- type RuntimeStatsConfig
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
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
Click to show internal directories.
Click to hide internal directories.