metrics

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector added in v0.7.0

type Collector interface {
	IncInsertion()
	AddInsertions(count int64)
	IncEviction(reason base.EvictionReason)
	AddEvictions(reason base.EvictionReason, count int64)
	IncHit()
	AddHits(count int64)
	IncMiss()
	AddMisses(count int64)
	UpdateSizeBytes(sizeBytes int64)
	UpdateLength(length int64)
}

Collector defines the interface for metric collection operations. This allows for both real Prometheus metrics and no-op implementations.

type InstrumentedCache added in v0.7.0

type InstrumentedCache[K comparable, V any] struct {
	// contains filtered or unexported fields
}

InstrumentedCache wraps any InMemoryCache implementation and adds metrics collection. It implements the InMemoryCache interface and delegates all operations to the underlying cache while tracking metrics for insertions, evictions, hits, and misses.

func NewInstrumentedCache added in v0.7.0

func NewInstrumentedCache[K comparable, V any](cache base.InMemoryCache[K, V], metrics Collector) *InstrumentedCache[K, V]

NewInstrumentedCache creates a new metrics wrapper around an existing cache.

func (*InstrumentedCache[K, V]) Algorithm added in v0.7.0

func (m *InstrumentedCache[K, V]) Algorithm() string

Algorithm returns the eviction algorithm name.

func (*InstrumentedCache[K, V]) Capacity added in v0.7.0

func (m *InstrumentedCache[K, V]) Capacity() int

Capacity returns the capacity of the cache.

func (*InstrumentedCache[K, V]) Delete added in v0.7.0

func (m *InstrumentedCache[K, V]) Delete(key K) bool

Delete removes a key from the cache and tracks eviction metrics.

func (*InstrumentedCache[K, V]) DeleteMany added in v0.7.0

func (m *InstrumentedCache[K, V]) DeleteMany(keys []K) map[K]bool

DeleteMany removes multiple keys from the cache and tracks eviction metrics.

func (*InstrumentedCache[K, V]) Get added in v0.7.0

func (m *InstrumentedCache[K, V]) Get(key K) (V, bool)

Get retrieves a value from the cache and tracks hit/miss metrics.

func (*InstrumentedCache[K, V]) GetMany added in v0.7.0

func (m *InstrumentedCache[K, V]) GetMany(keys []K) (map[K]V, []K)

GetMany retrieves multiple values from the cache and tracks hit/miss metrics.

func (*InstrumentedCache[K, V]) Has added in v0.7.0

func (m *InstrumentedCache[K, V]) Has(key K) bool

Has checks if a key exists in the cache and tracks hit/miss metrics.

func (*InstrumentedCache[K, V]) HasMany added in v0.7.0

func (m *InstrumentedCache[K, V]) HasMany(keys []K) map[K]bool

HasMany checks if multiple keys exist in the cache and tracks hit/miss metrics.

func (*InstrumentedCache[K, V]) Keys added in v0.7.0

func (m *InstrumentedCache[K, V]) Keys() []K

Keys returns all keys currently in the cache.

func (*InstrumentedCache[K, V]) Len added in v0.7.0

func (m *InstrumentedCache[K, V]) Len() int

Len returns the number of items in the cache.

func (*InstrumentedCache[K, V]) Peek added in v0.7.0

func (m *InstrumentedCache[K, V]) Peek(key K) (V, bool)

Peek retrieves a value from the cache without updating access order and tracks hit/miss metrics.

func (*InstrumentedCache[K, V]) PeekMany added in v0.7.0

func (m *InstrumentedCache[K, V]) PeekMany(keys []K) (map[K]V, []K)

PeekMany retrieves multiple values from the cache without updating access order and tracks hit/miss metrics.

func (*InstrumentedCache[K, V]) Purge added in v0.7.0

func (m *InstrumentedCache[K, V]) Purge()

Purge removes all items from the cache and tracks eviction metrics.

func (*InstrumentedCache[K, V]) Range added in v0.7.0

func (m *InstrumentedCache[K, V]) Range(f func(K, V) bool)

Range iterates over all key-value pairs in the cache.

func (*InstrumentedCache[K, V]) Set added in v0.7.0

func (m *InstrumentedCache[K, V]) Set(key K, value V)

Set stores a key-value pair in the cache and tracks insertion metrics.

func (*InstrumentedCache[K, V]) SetMany added in v0.7.0

func (m *InstrumentedCache[K, V]) SetMany(items map[K]V)

SetMany stores multiple key-value pairs in the cache and tracks insertion metrics.

func (*InstrumentedCache[K, V]) SizeBytes added in v0.7.0

func (m *InstrumentedCache[K, V]) SizeBytes() int64

SizeBytes returns the total size of all cache entries in bytes.

func (*InstrumentedCache[K, V]) Values added in v0.7.0

func (m *InstrumentedCache[K, V]) Values() []V

Values returns all values currently in the cache.

type NoOpCollector added in v0.7.0

type NoOpCollector struct{}

NoOpCollector is a no-op implementation of Collector that does nothing. This provides better performance than conditional checks when metrics are disabled.

func (*NoOpCollector) AddEvictions added in v0.7.0

func (n *NoOpCollector) AddEvictions(reason base.EvictionReason, count int64)

func (*NoOpCollector) AddHits added in v0.7.0

func (n *NoOpCollector) AddHits(count int64)

func (*NoOpCollector) AddInsertions added in v0.7.0

func (n *NoOpCollector) AddInsertions(count int64)

func (*NoOpCollector) AddMisses added in v0.7.0

func (n *NoOpCollector) AddMisses(count int64)

func (*NoOpCollector) IncEviction added in v0.7.0

func (n *NoOpCollector) IncEviction(reason base.EvictionReason)

func (*NoOpCollector) IncHit added in v0.7.0

func (n *NoOpCollector) IncHit()

func (*NoOpCollector) IncInsertion added in v0.7.0

func (n *NoOpCollector) IncInsertion()

func (*NoOpCollector) IncMiss added in v0.7.0

func (n *NoOpCollector) IncMiss()

func (*NoOpCollector) UpdateLength added in v0.7.0

func (n *NoOpCollector) UpdateLength(length int64)

func (*NoOpCollector) UpdateSizeBytes added in v0.7.0

func (n *NoOpCollector) UpdateSizeBytes(sizeBytes int64)

type PrometheusCollector added in v0.7.0

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

PrometheusCollector implements Collector using Prometheus metrics.

func NewPrometheusCollector added in v0.7.0

func NewPrometheusCollector(name string, shard int, mode base.CacheMode, capacity int, algorithm string, ttl *time.Duration, jitterLambda *float64, jitterUpperBound *time.Duration, stale *time.Duration, missingCapacity *int) *PrometheusCollector

NewPrometheusCollector creates a new Prometheus-based metric collector.

func (*PrometheusCollector) AddEvictions added in v0.7.0

func (p *PrometheusCollector) AddEvictions(reason base.EvictionReason, count int64)

AddEvictions atomically adds the specified count to the eviction counter for the given reason.

func (*PrometheusCollector) AddHits added in v0.7.0

func (p *PrometheusCollector) AddHits(count int64)

AddHits atomically adds the specified count to the hit counter.

func (*PrometheusCollector) AddInsertions added in v0.7.0

func (p *PrometheusCollector) AddInsertions(count int64)

AddInsertions atomically adds the specified count to the insertion counter.

func (*PrometheusCollector) AddMisses added in v0.7.0

func (p *PrometheusCollector) AddMisses(count int64)

AddMisses atomically adds the specified count to the miss counter.

func (*PrometheusCollector) Collect added in v0.7.0

func (p *PrometheusCollector) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector interface.

func (*PrometheusCollector) Describe added in v0.7.0

func (p *PrometheusCollector) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector interface.

func (*PrometheusCollector) IncEviction added in v0.7.0

func (p *PrometheusCollector) IncEviction(reason base.EvictionReason)

IncEviction atomically increments the eviction counter for the given reason.

func (*PrometheusCollector) IncHit added in v0.7.0

func (p *PrometheusCollector) IncHit()

IncHit atomically increments the hit counter.

func (*PrometheusCollector) IncInsertion added in v0.7.0

func (p *PrometheusCollector) IncInsertion()

IncInsertion atomically increments the insertion counter.

func (*PrometheusCollector) IncMiss added in v0.7.0

func (p *PrometheusCollector) IncMiss()

IncMiss atomically increments the miss counter.

func (*PrometheusCollector) UpdateLength added in v0.7.0

func (p *PrometheusCollector) UpdateLength(length int64)

UpdateLength atomically updates the cache length.

func (*PrometheusCollector) UpdateSizeBytes added in v0.7.0

func (p *PrometheusCollector) UpdateSizeBytes(sizeBytes int64)

UpdateSizeBytes atomically updates the cache size in bytes.

Jump to

Keyboard shortcuts

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