-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetric_collector.go
74 lines (57 loc) · 1.75 KB
/
metric_collector.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
package mgcache
import (
"github.com/prometheus/client_golang/prometheus"
)
const (
namespaceCache = "mgcache"
)
const (
metricValueCacheHit = "hit"
metricValueCacheMiss = "miss"
metricValueCacheSet = "set"
)
type (
// IMetricCollector is a wrapper for prometheus.Collector
IMetricCollector interface {
CacheHit(serviceID string, storeType string)
CacheMiss(serviceID string, storeType string)
CacheSet(serviceID string, storeType string)
}
metricCollector struct {
cacheBehaviorMetric *prometheus.CounterVec
}
emptyCollector struct {
}
)
func NewMetricCollector() IMetricCollector {
cacheBehaviorMetric := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "mgcache_behavior",
Namespace: namespaceCache,
Help: "This represent the number of items in cache",
},
[]string{"service", "store", "metric"},
)
defaultPrometheusRegisterer.MustRegister(cacheBehaviorMetric)
return &metricCollector{
cacheBehaviorMetric: cacheBehaviorMetric,
}
}
func NewEmptyCollector() IMetricCollector {
return &emptyCollector{}
}
func (m metricCollector) CacheHit(serviceID string, storeType string) {
m.cacheBehaviorMetric.WithLabelValues(serviceID, storeType, metricValueCacheHit).Inc()
}
func (m metricCollector) CacheMiss(serviceID string, storeType string) {
m.cacheBehaviorMetric.WithLabelValues(serviceID, storeType, metricValueCacheMiss).Inc()
}
func (m metricCollector) CacheSet(serviceID string, storeType string) {
m.cacheBehaviorMetric.WithLabelValues(serviceID, storeType, metricValueCacheSet).Inc()
}
func (e emptyCollector) CacheHit(serviceID string, storeType string) {
}
func (e emptyCollector) CacheMiss(serviceID string, storeType string) {
}
func (e emptyCollector) CacheSet(serviceID string, storeType string) {
}