-
Notifications
You must be signed in to change notification settings - Fork 147
/
peering.go
89 lines (78 loc) · 2.48 KB
/
peering.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
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/peering"
)
type PeeringMetricsProvider struct {
peerCount prometheus.Gauge
sendQueueLen prometheus.Gauge
sendMsgSizes prometheus.Histogram
recvQueueLen prometheus.Gauge
recvMsgSizes prometheus.Histogram
}
var _ peering.Metrics = &PeeringMetricsProvider{}
func NewPeeringMetricsProvider() *PeeringMetricsProvider {
msgCountBuckets := prometheus.ExponentialBucketsRange(1, 100_000, 17)
return &PeeringMetricsProvider{
peerCount: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "peering",
Name: "peer_count",
Help: "Number active of peers.",
}),
sendQueueLen: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "peering",
Name: "send_queue_len",
Help: "Size of the send queue.",
}),
sendMsgSizes: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "peering",
Name: "send_msg_sizes",
Help: "Sizes of the sent messages.",
Buckets: msgCountBuckets,
}),
recvQueueLen: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "iota_wasp",
Subsystem: "peering",
Name: "recv_queue_len",
Help: "Size of the recv queue.",
}),
recvMsgSizes: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "peering",
Name: "recv_msg_sizes",
Help: "Sizes of the received messages.",
Buckets: msgCountBuckets,
}),
}
}
func (m *PeeringMetricsProvider) Register(reg prometheus.Registerer) {
reg.MustRegister(
m.peerCount,
m.recvQueueLen,
m.recvMsgSizes,
m.sendQueueLen,
m.sendMsgSizes,
)
}
func (m *PeeringMetricsProvider) PeerCount(peerCount int) {
m.peerCount.Set(float64(peerCount))
}
func (m *PeeringMetricsProvider) RecvEnqueued(messageSize, newPipeSize int) {
m.recvQueueLen.Set(float64(newPipeSize))
m.recvMsgSizes.Observe(float64(messageSize))
}
func (m *PeeringMetricsProvider) RecvDequeued(messageSize, newPipeSize int) {
m.recvQueueLen.Set(float64(newPipeSize))
m.recvMsgSizes.Observe(float64(messageSize))
}
func (m *PeeringMetricsProvider) SendEnqueued(messageSize, newPipeSize int) {
m.sendQueueLen.Set(float64(newPipeSize))
m.sendMsgSizes.Observe(float64(messageSize))
}
func (m *PeeringMetricsProvider) SendDequeued(messageSize, newPipeSize int) {
m.sendQueueLen.Set(float64(newPipeSize))
m.sendMsgSizes.Observe(float64(messageSize))
}