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