metrics

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 3 Imported by: 0

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

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) RecordHit

func (c *CacheMetrics) RecordHit()

RecordHit records a cache hit

func (*CacheMetrics) RecordMiss

func (c *CacheMetrics) RecordMiss()

RecordMiss records a cache miss

func (*CacheMetrics) Reset

func (c *CacheMetrics) Reset()

Reset resets all cache metrics to zero

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

func NewCounter(name string) *Counter

NewCounter creates a new counter with a given name

func (*Counter) GetValue

func (c *Counter) GetValue() int64

GetValue returns the current value of the counter

func (*Counter) Increment

func (c *Counter) Increment()

Increment increments the counter by 1

func (*Counter) IncrementBy

func (c *Counter) IncrementBy(value int64)

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

func NewGauge

func NewGauge(name string) *Gauge

NewGauge creates a new gauge with a given name

func (*Gauge) Add

func (g *Gauge) Add(value float64)

Add adds the given value to the gauge

func (*Gauge) Decrement

func (g *Gauge) Decrement()

Decrement decrements the gauge by 1

func (*Gauge) GetValue

func (g *Gauge) GetValue() float64

GetValue returns the current value of the gauge

func (*Gauge) Increment

func (g *Gauge) Increment()

Increment increments the gauge by 1

func (*Gauge) Set

func (g *Gauge) Set(value float64)

Set sets the gauge to a specific value

func (*Gauge) Subtract

func (g *Gauge) Subtract(value float64)

Subtract subtracts the given value from the gauge

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) Reset

func (p *PoolMetrics) Reset()

Reset resets all pool metrics to zero

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 GetRegistry

func GetRegistry() *Registry

GetRegistry returns the singleton global registry

func (*Registry) Clear

func (r *Registry) Clear()

Clear removes all metrics from the registry

func (*Registry) GetAllCounters

func (r *Registry) GetAllCounters() map[string]*Counter

GetAllCounters returns all registered counters

func (*Registry) GetAllGauges

func (r *Registry) GetAllGauges() map[string]*Gauge

GetAllGauges returns all registered gauges

func (*Registry) GetAllRatioCounters

func (r *Registry) GetAllRatioCounters() map[string]*RatioCounter

GetAllRatioCounters returns all registered ratio counters

func (*Registry) GetAllTimers

func (r *Registry) GetAllTimers() map[string]*Timer

GetAllTimers returns all registered timers

func (*Registry) GetCounter

func (r *Registry) GetCounter(name string) *Counter

GetCounter gets a counter by name (or nil if not found)

func (*Registry) GetGauge

func (r *Registry) GetGauge(name string) *Gauge

GetGauge gets a gauge by name (or nil if not found)

func (*Registry) GetOrCreateCounter

func (r *Registry) GetOrCreateCounter(name string) *Counter

GetOrCreateCounter gets or creates a counter with the given name

func (*Registry) GetOrCreateGauge

func (r *Registry) GetOrCreateGauge(name string) *Gauge

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

func (r *Registry) GetOrCreateTimer(name string) *Timer

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)

func (*Registry) GetTimer

func (r *Registry) GetTimer(name string) *Timer

GetTimer gets a timer by name (or nil if not found)

type Timer

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

Timer tracks execution duration of operations

func NewTimer

func NewTimer(name string) *Timer

NewTimer creates a new timer with a given name

func (*Timer) GetAverageDuration

func (t *Timer) GetAverageDuration() time.Duration

GetAverageDuration returns the average duration of all timed operations

func (*Timer) GetCount

func (t *Timer) GetCount() int64

GetCount returns the number of timed operations

func (*Timer) GetLastDuration

func (t *Timer) GetLastDuration() time.Duration

GetLastDuration returns the duration of the last timed operation

func (*Timer) GetTotalDuration

func (t *Timer) GetTotalDuration() time.Duration

GetTotalDuration returns the total duration of all timed operations

func (*Timer) RecordDuration

func (t *Timer) RecordDuration(duration time.Duration)

RecordDuration manually records a duration without starting/stopping the timer

func (*Timer) Start

func (t *Timer) Start()

Start starts the timer

func (*Timer) Stop

func (t *Timer) Stop() time.Duration

Stop stops the timer and records the duration

func (*Timer) TimeFunction

func (t *Timer) TimeFunction(fn func() interface{}) interface{}

TimeFunction times the execution of a function and returns its result

Jump to

Keyboard shortcuts

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