-
Notifications
You must be signed in to change notification settings - Fork 23
/
dist-cache-metrics.go
119 lines (112 loc) · 4.59 KB
/
dist-cache-metrics.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package distcache
import (
"fmt"
"github.com/fluxninja/aperture/v2/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
// DistCacheMetrics holds metrics from DistCache, Olric, DMap statistics.
type DistCacheMetrics struct {
EntriesTotal *prometheus.GaugeVec
DeleteHits *prometheus.GaugeVec
DeleteMisses *prometheus.GaugeVec
GetMisses *prometheus.GaugeVec
GetHits *prometheus.GaugeVec
EvictedTotal *prometheus.GaugeVec
PartitionsCount *prometheus.GaugeVec
BackupPartitionsCount *prometheus.GaugeVec
FragmentMigrationEventsTotal *prometheus.CounterVec
FragmentReceivedEventsTotal *prometheus.CounterVec
PartitionsLength *prometheus.GaugeVec
BackupPartitionsLength *prometheus.GaugeVec
}
func newDistCacheMetrics() *DistCacheMetrics {
distCacheMetricsLabels := []string{
metrics.DistCacheMemberIDLabel,
metrics.DistCacheMemberNameLabel,
}
return &DistCacheMetrics{
EntriesTotal: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheEntriesTotalMetricName,
Help: "Total number of entries in the DMap.",
}, distCacheMetricsLabels),
DeleteHits: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheDeleteHitsMetricName,
Help: "Number of deletion requests resulting in an item being removed in the DMap.",
}, distCacheMetricsLabels),
DeleteMisses: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheDeleteMissesMetricName,
Help: "Number of deletion requests for missing keys in the DMap.",
}, distCacheMetricsLabels),
GetMisses: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheGetMissesMetricName,
Help: "Number of entries that have been requested and not found in the DMap.",
}, distCacheMetricsLabels),
GetHits: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheGetHitsMetricName,
Help: "Number of entries that have been requested and found present in the DMap.",
}, distCacheMetricsLabels),
EvictedTotal: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheEvictedTotalMetricName,
Help: "Total number of entries removed from cache to free memory for new entries in the DMap.",
}, distCacheMetricsLabels),
PartitionsCount: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCachePartitionsCountMetricsName,
Help: "Current number of non-empty partitions owned by given node.",
}, distCacheMetricsLabels),
BackupPartitionsCount: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheBackupPartitionsCountMetricsName,
Help: "Current number of non-empty backup partitions owned by given node.",
}, distCacheMetricsLabels),
FragmentMigrationEventsTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: metrics.DistCacheFragmentMigrationEventsTotalMetricsName,
Help: "Cumulative number of fragment migration (outgoing) events.",
}, distCacheMetricsLabels),
FragmentReceivedEventsTotal: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: metrics.DistCacheFragmentReceivedEventsTotalMetricsName,
Help: "Cumulative number of fragment received (incoming) events.",
}, distCacheMetricsLabels),
PartitionsLength: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCachePartitionsLength,
Help: "Current length of partitions of given node.",
}, distCacheMetricsLabels),
BackupPartitionsLength: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: metrics.DistCacheBackupPartitionsLength,
Help: "Current length of backup partitions of given node.",
}, distCacheMetricsLabels),
}
}
func (dm *DistCacheMetrics) allMetrics() []prometheus.Collector {
return []prometheus.Collector{
dm.EntriesTotal,
dm.DeleteHits,
dm.DeleteMisses,
dm.GetMisses,
dm.GetHits,
dm.EvictedTotal,
dm.PartitionsCount,
dm.BackupPartitionsCount,
dm.FragmentMigrationEventsTotal,
dm.FragmentReceivedEventsTotal,
dm.PartitionsLength,
dm.BackupPartitionsLength,
}
}
func (dm *DistCacheMetrics) registerMetrics(prometheusRegistry *prometheus.Registry) error {
for _, m := range dm.allMetrics() {
err := prometheusRegistry.Register(m)
if err != nil {
if _, ok := err.(prometheus.AlreadyRegisteredError); !ok {
return fmt.Errorf("unable to register distcache metrics: %v", err)
}
}
}
return nil
}
func (dm *DistCacheMetrics) unregisterMetrics(prometheusRegistry *prometheus.Registry) error {
for _, m := range dm.allMetrics() {
if !prometheusRegistry.Unregister(m) {
return fmt.Errorf("unable to unregister distcache metrics")
}
}
return nil
}