From 4b69da2d0362d10750acb45d16a5a897875748c3 Mon Sep 17 00:00:00 2001 From: bakins Date: Thu, 2 Jan 2020 10:06:04 -0500 Subject: [PATCH] mapper cache: Add cache metrics for total gets and hits Add metrics to record mapper cache hits and total gets. Signed-off-by: bakins --- pkg/mapper/mapper_cache.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/mapper/mapper_cache.go b/pkg/mapper/mapper_cache.go index 9340bc8..988c34d 100644 --- a/pkg/mapper/mapper_cache.go +++ b/pkg/mapper/mapper_cache.go @@ -25,6 +25,18 @@ var ( Help: "The count of unique metrics currently cached.", }, ) + cacheGetsTotal = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "mapping_cache_gets_total", + Help: "The count of total cache gets.", + }, + ) + cacheHitsTotal = prometheus.NewCounter( + prometheus.CounterOpts{ + Name: "mapping_cache_hits_total", + Help: "The count of total cache hits.", + }, + ) ) type MetricMapperCacheResult struct { @@ -58,7 +70,9 @@ func NewMetricMapperCache(size int) (*MetricMapperLRUCache, error) { } func (m *MetricMapperLRUCache) Get(metricString string, metricType MetricType) (*MetricMapperCacheResult, bool) { + cacheGetsTotal.Inc() if result, ok := m.cache.Get(formatKey(metricString, metricType)); ok { + cacheHitsTotal.Inc() return result.(*MetricMapperCacheResult), true } else { return nil, false @@ -102,4 +116,6 @@ func (m *MetricMapperNoopCache) AddMiss(metricString string, metricType MetricTy func init() { prometheus.MustRegister(cacheLength) + prometheus.MustRegister(cacheGetsTotal) + prometheus.MustRegister(cacheHitsTotal) }