Documentation
¶
Overview ¶
ABOUTME: Metrics collection and reporting for monitoring system performance. ABOUTME: Cache and pool metrics with pluggable backend support. Package metrics provides instrumentation for monitoring system performance and resource usage. It includes specialized metrics for cache efficiency, connection pool utilization, and general application metrics with support for various metrics backends.
Metrics categories:
- Cache hit/miss ratios
- Pool utilization metrics
- Request latency tracking
- Error rate monitoring
- Resource usage statistics
- Custom metric types
Package metrics provides utilities for collecting and reporting performance metrics in the Go-LLMs project. It supports various metric types including counters, gauges, ratio counters, and timers, all with thread-safe operations.
Index ¶
- type CacheMetrics
- func (c *CacheMetrics) GetAverageAccessTime() time.Duration
- func (c *CacheMetrics) GetHitRate() float64
- func (c *CacheMetrics) GetHitsMisses() (int64, int64, int64)
- func (c *CacheMetrics) RecordAccessTime(duration time.Duration)
- func (c *CacheMetrics) RecordHit()
- func (c *CacheMetrics) RecordMiss()
- func (c *CacheMetrics) Reset()
- func (c *CacheMetrics) TimeAccess(fn func() (interface{}, bool)) (interface{}, bool)
- type Counter
- type Gauge
- type PoolMetrics
- func (p *PoolMetrics) GetAllocationCount() (int64, int64)
- func (p *PoolMetrics) GetAverageAllocationTime() time.Duration
- func (p *PoolMetrics) GetAverageWaitTime() time.Duration
- func (p *PoolMetrics) GetPoolSize() int64
- func (p *PoolMetrics) IncrementPoolSize(delta int64)
- func (p *PoolMetrics) RecordAllocation()
- func (p *PoolMetrics) RecordAllocationTime(duration time.Duration)
- func (p *PoolMetrics) RecordReturn()
- func (p *PoolMetrics) RecordWaitTime(duration time.Duration)
- func (p *PoolMetrics) Reset()
- func (p *PoolMetrics) SetPoolSize(size int64)
- func (p *PoolMetrics) TimeAllocation(fn func() interface{}) interface{}
- type RatioCounter
- type Registry
- func (r *Registry) Clear()
- func (r *Registry) GetAllCounters() map[string]*Counter
- func (r *Registry) GetAllGauges() map[string]*Gauge
- func (r *Registry) GetAllRatioCounters() map[string]*RatioCounter
- func (r *Registry) GetAllTimers() map[string]*Timer
- func (r *Registry) GetCounter(name string) *Counter
- func (r *Registry) GetGauge(name string) *Gauge
- func (r *Registry) GetOrCreateCounter(name string) *Counter
- func (r *Registry) GetOrCreateGauge(name string) *Gauge
- func (r *Registry) GetOrCreateRatioCounter(name string) *RatioCounter
- func (r *Registry) GetOrCreateTimer(name string) *Timer
- func (r *Registry) GetRatioCounter(name string) *RatioCounter
- func (r *Registry) GetTimer(name string) *Timer
- type Timer
- func (t *Timer) GetAverageDuration() time.Duration
- func (t *Timer) GetCount() int64
- func (t *Timer) GetLastDuration() time.Duration
- func (t *Timer) GetTotalDuration() time.Duration
- func (t *Timer) RecordDuration(duration time.Duration)
- func (t *Timer) Start()
- func (t *Timer) Stop() time.Duration
- func (t *Timer) TimeFunction(fn func() interface{}) interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheMetrics ¶
type CacheMetrics struct {
// contains filtered or unexported fields
}
CacheMetrics tracks cache hit/miss statistics
func NewCacheMetrics ¶
func NewCacheMetrics(name string) *CacheMetrics
NewCacheMetrics creates a new cache metrics collector with the given name
func (*CacheMetrics) GetAverageAccessTime ¶
func (c *CacheMetrics) GetAverageAccessTime() time.Duration
GetAverageAccessTime returns the average time taken to access the cache
func (*CacheMetrics) GetHitRate ¶
func (c *CacheMetrics) GetHitRate() float64
GetHitRate returns the current cache hit rate
func (*CacheMetrics) GetHitsMisses ¶
func (c *CacheMetrics) GetHitsMisses() (int64, int64, int64)
GetHitsMisses returns the current cache hits, misses, and total accesses
func (*CacheMetrics) RecordAccessTime ¶
func (c *CacheMetrics) RecordAccessTime(duration time.Duration)
RecordAccessTime records the time taken to access the cache
func (*CacheMetrics) RecordMiss ¶
func (c *CacheMetrics) RecordMiss()
RecordMiss records a cache miss
func (*CacheMetrics) TimeAccess ¶
func (c *CacheMetrics) TimeAccess(fn func() (interface{}, bool)) (interface{}, bool)
TimeAccess times a cache access operation and records the result
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a monotonically increasing counter
func NewCounter ¶
NewCounter creates a new counter with a given name
func (*Counter) IncrementBy ¶
IncrementBy increments the counter by the specified value
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a metric that can go up and down
type PoolMetrics ¶
type PoolMetrics struct {
// contains filtered or unexported fields
}
PoolMetrics tracks memory pool statistics
func NewPoolMetrics ¶
func NewPoolMetrics(name string) *PoolMetrics
NewPoolMetrics creates a new pool metrics collector with the given name
func (*PoolMetrics) GetAllocationCount ¶
func (p *PoolMetrics) GetAllocationCount() (int64, int64)
GetAllocationCount returns the number of allocations and returns
func (*PoolMetrics) GetAverageAllocationTime ¶
func (p *PoolMetrics) GetAverageAllocationTime() time.Duration
GetAverageAllocationTime returns the average time to allocate a new object
func (*PoolMetrics) GetAverageWaitTime ¶
func (p *PoolMetrics) GetAverageWaitTime() time.Duration
GetAverageWaitTime returns the average time waiting for an object
func (*PoolMetrics) GetPoolSize ¶
func (p *PoolMetrics) GetPoolSize() int64
GetPoolSize returns the current pool size
func (*PoolMetrics) IncrementPoolSize ¶
func (p *PoolMetrics) IncrementPoolSize(delta int64)
IncrementPoolSize adds to the current pool size
func (*PoolMetrics) RecordAllocation ¶
func (p *PoolMetrics) RecordAllocation()
RecordAllocation records an object allocation from the pool
func (*PoolMetrics) RecordAllocationTime ¶
func (p *PoolMetrics) RecordAllocationTime(duration time.Duration)
RecordAllocationTime records the time taken to allocate a new object
func (*PoolMetrics) RecordReturn ¶
func (p *PoolMetrics) RecordReturn()
RecordReturn records an object being returned to the pool
func (*PoolMetrics) RecordWaitTime ¶
func (p *PoolMetrics) RecordWaitTime(duration time.Duration)
RecordWaitTime records the time waiting for an object from the pool
func (*PoolMetrics) SetPoolSize ¶
func (p *PoolMetrics) SetPoolSize(size int64)
SetPoolSize sets the current pool size
func (*PoolMetrics) TimeAllocation ¶
func (p *PoolMetrics) TimeAllocation(fn func() interface{}) interface{}
TimeAllocation times the allocation of a new object
type RatioCounter ¶
type RatioCounter struct {
// contains filtered or unexported fields
}
RatioCounter tracks a ratio between two counters (e.g., cache hit rate)
func NewRatioCounter ¶
func NewRatioCounter(name string) *RatioCounter
NewRatioCounter creates a new ratio counter with a given name
func (*RatioCounter) GetRatio ¶
func (r *RatioCounter) GetRatio() float64
GetRatio returns the current ratio (numerator/denominator) Returns 0 if denominator is 0 to avoid division by zero
func (*RatioCounter) GetValues ¶
func (r *RatioCounter) GetValues() (int64, int64)
GetValues returns the raw numerator and denominator values
func (*RatioCounter) IncrementDenominator ¶
func (r *RatioCounter) IncrementDenominator()
IncrementDenominator increments the denominator by 1
func (*RatioCounter) IncrementDenominatorBy ¶
func (r *RatioCounter) IncrementDenominatorBy(value int64)
IncrementDenominatorBy increments the denominator by the specified value
func (*RatioCounter) IncrementNumerator ¶
func (r *RatioCounter) IncrementNumerator()
IncrementNumerator increments the numerator by 1
func (*RatioCounter) IncrementNumeratorBy ¶
func (r *RatioCounter) IncrementNumeratorBy(value int64)
IncrementNumeratorBy increments the numerator by the specified value
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a central registry for all metrics
func (*Registry) GetAllCounters ¶
GetAllCounters returns all registered counters
func (*Registry) GetAllGauges ¶
GetAllGauges returns all registered gauges
func (*Registry) GetAllRatioCounters ¶
func (r *Registry) GetAllRatioCounters() map[string]*RatioCounter
GetAllRatioCounters returns all registered ratio counters
func (*Registry) GetAllTimers ¶
GetAllTimers returns all registered timers
func (*Registry) GetCounter ¶
GetCounter gets a counter by name (or nil if not found)
func (*Registry) GetOrCreateCounter ¶
GetOrCreateCounter gets or creates a counter with the given name
func (*Registry) GetOrCreateGauge ¶
GetOrCreateGauge gets or creates a gauge with the given name
func (*Registry) GetOrCreateRatioCounter ¶
func (r *Registry) GetOrCreateRatioCounter(name string) *RatioCounter
GetOrCreateRatioCounter gets or creates a ratio counter with the given name
func (*Registry) GetOrCreateTimer ¶
GetOrCreateTimer gets or creates a timer with the given name
func (*Registry) GetRatioCounter ¶
func (r *Registry) GetRatioCounter(name string) *RatioCounter
GetRatioCounter gets a ratio counter by name (or nil if not found)
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer tracks execution duration of operations
func (*Timer) GetAverageDuration ¶
GetAverageDuration returns the average duration of all timed operations
func (*Timer) GetLastDuration ¶
GetLastDuration returns the duration of the last timed operation
func (*Timer) GetTotalDuration ¶
GetTotalDuration returns the total duration of all timed operations
func (*Timer) RecordDuration ¶
RecordDuration manually records a duration without starting/stopping the timer
func (*Timer) TimeFunction ¶
func (t *Timer) TimeFunction(fn func() interface{}) interface{}
TimeFunction times the execution of a function and returns its result