From 9e5ef371ae322c68e920c26cd8be88ba69678a81 Mon Sep 17 00:00:00 2001 From: Axel Fahy Date: Fri, 16 Feb 2024 10:31:00 +0100 Subject: [PATCH] Add all ristretto metrics in options --- options.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/options.go b/options.go index e3c65aa..c12bf09 100644 --- a/options.go +++ b/options.go @@ -79,6 +79,87 @@ func WithHitsRatioGaugeMetric() Option { }) } +func WithKeysAddedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_keys_added_total", + Help: "The number of added keys in the cache.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.KeysAdded()) }, + }) +} + +func WithKeysUpdatedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_keys_updated_total", + Help: "The number of updated keys in the cache.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.KeysUpdated()) }, + }) +} + +func WithKeysEvictedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_keys_evicted_total", + Help: "The number of evicted keys from the cache.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.KeysEvicted()) }, + }) +} + +func WithCostAddedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_cost_added_total", + Help: "The sum of costs that have been added.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.CostAdded()) }, + }) +} + +func WithCostEvictedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_cost_evicted_total", + Help: "The sum of all costs that have been evicted.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.CostEvicted()) }, + }) +} + +func WithSetsDroppedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_sets_dropped_total", + Help: "The number of Set calls that don't make it into internal buffers.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.SetsDropped()) }, + }) +} + +func WithSetsRejectedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_sets_rejected_total", + Help: "The number of Set calls rejected by the policy.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.SetsRejected()) }, + }) +} + +func WithGetsDroppedMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_gets_dropped_total", + Help: "The number of Get counter increments that are dropped.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.GetsDropped()) }, + }) +} + +func WithGetsKeptMetric() Option { + return WithMetric(Desc{ + Name: "ristretto_gets_kept_total", + Help: "The number of Get counter increments that are kept.", + ValueType: prometheus.CounterValue, + Extractor: func(m *ristretto.Metrics) float64 { return float64(m.GetsKept()) }, + }) +} + func WithMetric(d Desc) Option { return func(o *config) { o.metrics = append(o.metrics, d)