mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-22 15:30:59 +00:00
mapper cache: Add cache metrics for total gets and hits
Add metrics to record mapper cache hits and total gets. Signed-off-by: bakins <brian@akins.org>
This commit is contained in:
parent
2e3d3ab962
commit
4b69da2d03
1 changed files with 16 additions and 0 deletions
|
@ -25,6 +25,18 @@ var (
|
||||||
Help: "The count of unique metrics currently cached.",
|
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 {
|
type MetricMapperCacheResult struct {
|
||||||
|
@ -58,7 +70,9 @@ func NewMetricMapperCache(size int) (*MetricMapperLRUCache, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MetricMapperLRUCache) Get(metricString string, metricType MetricType) (*MetricMapperCacheResult, bool) {
|
func (m *MetricMapperLRUCache) Get(metricString string, metricType MetricType) (*MetricMapperCacheResult, bool) {
|
||||||
|
cacheGetsTotal.Inc()
|
||||||
if result, ok := m.cache.Get(formatKey(metricString, metricType)); ok {
|
if result, ok := m.cache.Get(formatKey(metricString, metricType)); ok {
|
||||||
|
cacheHitsTotal.Inc()
|
||||||
return result.(*MetricMapperCacheResult), true
|
return result.(*MetricMapperCacheResult), true
|
||||||
} else {
|
} else {
|
||||||
return nil, false
|
return nil, false
|
||||||
|
@ -102,4 +116,6 @@ func (m *MetricMapperNoopCache) AddMiss(metricString string, metricType MetricTy
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(cacheLength)
|
prometheus.MustRegister(cacheLength)
|
||||||
|
prometheus.MustRegister(cacheGetsTotal)
|
||||||
|
prometheus.MustRegister(cacheHitsTotal)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue