-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
metrics.go
118 lines (109 loc) · 4.09 KB
/
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
package rhh
import (
"sort"
"github.com/prometheus/client_golang/prometheus"
)
type Metrics struct {
LoadFactor *prometheus.GaugeVec // Load factor of the hashmap.
Size *prometheus.GaugeVec // Number of items in hashmap.
GetDuration *prometheus.HistogramVec // Sample of get times.
LastGetDuration *prometheus.GaugeVec // Sample of most recent get time.
InsertDuration *prometheus.HistogramVec // Sample of insertion times.
LastInsertDuration *prometheus.GaugeVec // Sample of most recent insertion time.
LastGrowDuration *prometheus.GaugeVec // Most recent growth time.
MeanProbeCount *prometheus.GaugeVec // Average number of probes for each element.
// These metrics have an extra label status = {"hit", "miss"}
Gets *prometheus.CounterVec // Number of times item retrieved.
Puts *prometheus.CounterVec // Number of times item inserted.
}
// NewMetrics initialises prometheus metrics for tracking an RHH hashmap.
func NewMetrics(namespace, subsystem string, labels prometheus.Labels) *Metrics {
var names []string
for k := range labels {
names = append(names, k)
}
sort.Strings(names)
getPutNames := append(append([]string(nil), names...), "status")
sort.Strings(getPutNames)
return &Metrics{
LoadFactor: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "load_percent",
Help: "Load factor of the hashmap.",
}, names),
Size: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "size",
Help: "Number of items in the hashmap.",
}, names),
GetDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "get_duration_ns",
Help: "Times taken to retrieve elements in nanoseconds (sampled every 10% of retrievals).",
// 15 buckets spaced exponentially between 100 and ~30,000.
Buckets: prometheus.ExponentialBuckets(100., 1.5, 15),
}, names),
LastGetDuration: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "get_duration_last_ns",
Help: "Last retrieval duration in nanoseconds (sampled every 10% of retrievals)",
}, names),
InsertDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "put_duration_ns",
Help: "Times taken to insert elements in nanoseconds (sampled every 10% of insertions).",
// 15 buckets spaced exponentially between 100 and ~30,000.
Buckets: prometheus.ExponentialBuckets(100., 1.5, 15),
}, names),
LastInsertDuration: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "put_duration_last_ns",
Help: "Last insertion duration in nanoseconds (sampled every 10% of insertions)",
}, names),
LastGrowDuration: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "grow_duration_s",
Help: "Time in seconds to last grow the hashmap.",
}, names),
MeanProbeCount: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "mean_probes",
Help: "Average probe count of all elements (sampled every 0.5% of insertions).",
}, names),
Gets: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "get_total",
Help: "Number of times elements retrieved.",
}, getPutNames),
Puts: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "put_total",
Help: "Number of times elements inserted.",
}, getPutNames),
}
}
// PrometheusCollectors satisfies the prom.PrometheusCollector interface.
func (m *Metrics) PrometheusCollectors() []prometheus.Collector {
return []prometheus.Collector{
m.LoadFactor,
m.Size,
m.GetDuration,
m.LastGetDuration,
m.InsertDuration,
m.LastInsertDuration,
m.LastGrowDuration,
m.MeanProbeCount,
m.Gets,
m.Puts,
}
}