Documentation
¶
Overview ¶
Package prometheusmetrics records httpcache activity into Prometheus.
It lives in its own package so that importing httpcache does not drag in prometheus/client_golang -- and with it protobuf -- for a service that never exports metrics. Measured for a program importing only the root package: 51 fewer linked packages, 17 fewer modules and a 32.5% smaller binary.
The root package defines what is recorded (httpcache.Metrics); this package decides where it goes. Nothing about cache behaviour lives here.
registry := metrics.NewRegistry("myproxy")
prometheusmetrics.New(registry) // installs itself as the default recorder
Index ¶
- type Metrics
- func (m *Metrics) RecordCacheEviction(reason string)
- func (m *Metrics) RecordCacheHit(method string)
- func (m *Metrics) RecordCacheMiss(method string)
- func (m *Metrics) RecordCacheSkip()
- func (m *Metrics) RecordCleanupDuration(durationSeconds float64)
- func (m *Metrics) RecordRetrieveOperation(found bool)
- func (m *Metrics) RecordStoreOperation(success bool)
- func (m *Metrics) RecordUpstreamDuration(method string, status int, durationSeconds float64)
- func (m *Metrics) RecordUpstreamError(errorType string)
- func (m *Metrics) SetCacheItemCount(count int)
- func (m *Metrics) SetCacheSize(sizeBytes int64)
- func (m *Metrics) SetCacheStaleCount(count int)
- func (m *Metrics) UpdateCacheStats(stats httpcache.CacheStats)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
type Metrics struct {
// CacheHits tracks the number of cache hits
CacheHits *prometheus.CounterVec
// CacheMisses tracks the number of cache misses
CacheMisses *prometheus.CounterVec
// CacheSkips tracks the number of cache skips (non-cacheable requests)
CacheSkips prometheus.Counter
// UpstreamDuration tracks the duration of upstream requests
UpstreamDuration *prometheus.HistogramVec
// CacheSizeBytes tracks the current cache size in bytes (gauge)
CacheSizeBytes prometheus.Gauge
// CacheItemCount tracks the current number of cached items (gauge)
CacheItemCount prometheus.Gauge
// CacheStaleCount tracks the current number of stale map entries (gauge)
CacheStaleCount prometheus.Gauge
// UpstreamErrors tracks the number of upstream errors
UpstreamErrors *prometheus.CounterVec
// CacheStoreOperations tracks cache store operations
CacheStoreOperations *prometheus.CounterVec
// CacheRetrieveOperations tracks cache retrieve operations
CacheRetrieveOperations *prometheus.CounterVec
// CacheEvictions tracks the number of cache evictions
CacheEvictions *prometheus.CounterVec
// CacheCleanupDuration tracks the duration of cleanup operations
CacheCleanupDuration prometheus.Histogram
}
Metrics records cache activity into Prometheus collectors.
func New ¶
New creates and registers the cache collectors on registry, installs the result as httpcache's default recorder, and returns it.
func (*Metrics) RecordCacheEviction ¶
RecordCacheEviction records a cache eviction
func (*Metrics) RecordCacheHit ¶
RecordCacheHit records a cache hit
func (*Metrics) RecordCacheMiss ¶
RecordCacheMiss records a cache miss
func (*Metrics) RecordCacheSkip ¶
func (m *Metrics) RecordCacheSkip()
RecordCacheSkip records a cache skip
func (*Metrics) RecordCleanupDuration ¶
RecordCleanupDuration records the duration of a cleanup operation
func (*Metrics) RecordRetrieveOperation ¶
RecordRetrieveOperation records a cache retrieve operation
func (*Metrics) RecordStoreOperation ¶
RecordStoreOperation records a cache store operation
func (*Metrics) RecordUpstreamDuration ¶
RecordUpstreamDuration records the duration of an upstream request
func (*Metrics) RecordUpstreamError ¶
RecordUpstreamError records an upstream error
func (*Metrics) SetCacheItemCount ¶
SetCacheItemCount sets the current number of cached items
func (*Metrics) SetCacheSize ¶
SetCacheSize sets the current cache size in bytes
func (*Metrics) SetCacheStaleCount ¶
SetCacheStaleCount sets the current number of stale map entries
func (*Metrics) UpdateCacheStats ¶
func (m *Metrics) UpdateCacheStats(stats httpcache.CacheStats)
UpdateCacheStats updates all cache gauge metrics from stats