github.com/ethersphere/bee/v2@v2.2.0/pkg/storage/cache/metrics.go (about) 1 // Copyright 2023 The Swarm Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package cache 6 7 import ( 8 m "github.com/ethersphere/bee/v2/pkg/metrics" 9 "github.com/prometheus/client_golang/prometheus" 10 ) 11 12 type metrics struct { 13 CacheHit prometheus.Counter 14 CacheMiss prometheus.Counter 15 } 16 17 func newMetrics() metrics { 18 subsystem := "storage_cache" 19 20 return metrics{ 21 CacheHit: prometheus.NewCounter(prometheus.CounterOpts{ 22 Namespace: m.Namespace, 23 Subsystem: subsystem, 24 Name: "cache_hit", 25 Help: "Total cache hits.", 26 }), 27 CacheMiss: prometheus.NewCounter(prometheus.CounterOpts{ 28 Namespace: m.Namespace, 29 Subsystem: subsystem, 30 Name: "cache_miss", 31 Help: "Total cache misses.", 32 }), 33 } 34 } 35 36 func (c *Cache) Metrics() []prometheus.Collector { 37 return m.PrometheusCollectorsFromFields(c.metrics) 38 }