prometheusmetrics

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

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

func New(registry *metrics.Registry) *Metrics

New creates and registers the cache collectors on registry, installs the result as httpcache's default recorder, and returns it.

func (*Metrics) RecordCacheEviction

func (m *Metrics) RecordCacheEviction(reason string)

RecordCacheEviction records a cache eviction

func (*Metrics) RecordCacheHit

func (m *Metrics) RecordCacheHit(method string)

RecordCacheHit records a cache hit

func (*Metrics) RecordCacheMiss

func (m *Metrics) RecordCacheMiss(method string)

RecordCacheMiss records a cache miss

func (*Metrics) RecordCacheSkip

func (m *Metrics) RecordCacheSkip()

RecordCacheSkip records a cache skip

func (*Metrics) RecordCleanupDuration

func (m *Metrics) RecordCleanupDuration(durationSeconds float64)

RecordCleanupDuration records the duration of a cleanup operation

func (*Metrics) RecordRetrieveOperation

func (m *Metrics) RecordRetrieveOperation(found bool)

RecordRetrieveOperation records a cache retrieve operation

func (*Metrics) RecordStoreOperation

func (m *Metrics) RecordStoreOperation(success bool)

RecordStoreOperation records a cache store operation

func (*Metrics) RecordUpstreamDuration

func (m *Metrics) RecordUpstreamDuration(method string, status int, durationSeconds float64)

RecordUpstreamDuration records the duration of an upstream request

func (*Metrics) RecordUpstreamError

func (m *Metrics) RecordUpstreamError(errorType string)

RecordUpstreamError records an upstream error

func (*Metrics) SetCacheItemCount

func (m *Metrics) SetCacheItemCount(count int)

SetCacheItemCount sets the current number of cached items

func (*Metrics) SetCacheSize

func (m *Metrics) SetCacheSize(sizeBytes int64)

SetCacheSize sets the current cache size in bytes

func (*Metrics) SetCacheStaleCount

func (m *Metrics) SetCacheStaleCount(count int)

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

Jump to

Keyboard shortcuts

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