-
Notifications
You must be signed in to change notification settings - Fork 179
/
cache.go
61 lines (49 loc) · 1.87 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
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
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}),
misses: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "misses_total",
Namespace: namespaceStorage,
Subsystem: subsystemCache,
Help: "the number of misses for the cache",
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()
}
// CacheMiss records the number of misses in the node identities cache.
func (cc *CacheCollector) CacheMiss(resource string) {
cc.misses.With(prometheus.Labels{LabelResource: resource}).Inc()
}