Skip to content

Commit

Permalink
Merge pull request #1 from axelfahy/feature/options-for-all-metrics
Browse files Browse the repository at this point in the history
Add all ristretto metrics in options
  • Loading branch information
wolfmetr authored Feb 16, 2024
2 parents 8b684de + 9e5ef37 commit e1d7710
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e1d7710

Please sign in to comment.