-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
66 lines (56 loc) · 1.47 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
package batsub
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
)
// metrics prefix and label
const (
Batsub = "batsub"
Subscription = "subscription"
)
// Metrics stores Batcher Metrics.
type Metrics struct {
// State
PendingMessages *prometheus.GaugeVec
// Results
ProcessedMessages *prometheus.CounterVec
ProcessedBatches *prometheus.CounterVec
// Latencies
ProcessingLatency *prometheus.HistogramVec
}
// NewMetrics returns prefixed metrics.
func NewMetrics(prefix ...string) *Metrics {
ns := strings.Join(prefix, "_")
if len(ns) == 0 {
ns = Batsub
}
label := []string{Subscription}
return &Metrics{
// State
PendingMessages: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "pending_messages",
Namespace: ns,
}, label),
// Results
ProcessedMessages: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "processed_messages_total",
Namespace: ns,
}, label),
ProcessedBatches: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "processed_batches_total",
Namespace: ns,
}, label),
// Latencies
ProcessingLatency: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "processing_latency_seconds",
Namespace: ns,
}, label),
}
}
// Register registers all metrics.
func (m *Metrics) Register(reg prometheus.Registerer) {
reg.MustRegister(m.PendingMessages)
reg.MustRegister(m.ProcessedBatches)
reg.MustRegister(m.ProcessedMessages)
reg.MustRegister(m.ProcessingLatency)
}