github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/metrics/cache.go (about) 1 package metrics 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 "github.com/prometheus/client_golang/prometheus/promauto" 6 7 "github.com/onflow/flow-go/model/flow" 8 ) 9 10 type CacheCollector struct { 11 entries *prometheus.GaugeVec 12 hits *prometheus.CounterVec 13 notfounds *prometheus.CounterVec 14 misses *prometheus.CounterVec 15 } 16 17 func NewCacheCollector(chain flow.ChainID) *CacheCollector { 18 19 cm := &CacheCollector{ 20 21 entries: promauto.NewGaugeVec(prometheus.GaugeOpts{ 22 Name: "entries_total", 23 Namespace: namespaceStorage, 24 Subsystem: subsystemCache, 25 Help: "the number of entries in the cache", 26 ConstLabels: prometheus.Labels{LabelChain: chain.String()}, 27 }, []string{LabelResource}), 28 29 hits: promauto.NewCounterVec(prometheus.CounterOpts{ 30 Name: "hits_total", 31 Namespace: namespaceStorage, 32 Subsystem: subsystemCache, 33 Help: "the number of hits for the cache", 34 ConstLabels: prometheus.Labels{LabelChain: chain.String()}, 35 }, []string{LabelResource}), 36 37 notfounds: promauto.NewCounterVec(prometheus.CounterOpts{ 38 Name: "notfounds_total", 39 Namespace: namespaceStorage, 40 Subsystem: subsystemCache, 41 Help: "the number of times the queried item was not found in either cache or database", 42 ConstLabels: prometheus.Labels{LabelChain: chain.String()}, 43 }, []string{LabelResource}), 44 45 misses: promauto.NewCounterVec(prometheus.CounterOpts{ 46 Name: "misses_total", 47 Namespace: namespaceStorage, 48 Subsystem: subsystemCache, 49 Help: "the number of times the queried item was not found in cache, but found in database", 50 ConstLabels: prometheus.Labels{LabelChain: chain.String()}, 51 }, []string{LabelResource}), 52 } 53 54 return cm 55 } 56 57 // CacheEntries records the size of the node identities cache. 58 func (cc *CacheCollector) CacheEntries(resource string, entries uint) { 59 cc.entries.With(prometheus.Labels{LabelResource: resource}).Set(float64(entries)) 60 } 61 62 // CacheHit records the number of hits in the node identities cache. 63 func (cc *CacheCollector) CacheHit(resource string) { 64 cc.hits.With(prometheus.Labels{LabelResource: resource}).Inc() 65 } 66 67 // CacheNotFound records the number of times the queried item was not found in either cache 68 // or database. 69 func (cc *CacheCollector) CacheNotFound(resource string) { 70 cc.notfounds.With(prometheus.Labels{LabelResource: resource}).Inc() 71 } 72 73 // CacheMiss report the number of times the queried item is not found in the cache, but found in the database. 74 func (cc *CacheCollector) CacheMiss(resource string) { 75 cc.misses.With(prometheus.Labels{LabelResource: resource}).Inc() 76 }