-
Notifications
You must be signed in to change notification settings - Fork 338
/
metrics.go
125 lines (119 loc) · 4.46 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
119
120
121
122
123
124
125
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libp2p
import (
m "github.com/ethersphere/bee/v2/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type metrics struct {
// all metrics fields must be exported
// to be able to return them by Metrics()
// using reflection
CreatedConnectionCount prometheus.Counter
HandledConnectionCount prometheus.Counter
CreatedStreamCount prometheus.Counter
ClosedStreamCount prometheus.Counter
StreamResetCount prometheus.Counter
HandledStreamCount prometheus.Counter
BlocklistedPeerCount prometheus.Counter
BlocklistedPeerErrCount prometheus.Counter
DisconnectCount prometheus.Counter
ConnectBreakerCount prometheus.Counter
UnexpectedProtocolReqCount prometheus.Counter
KickedOutPeersCount prometheus.Counter
StreamHandlerErrResetCount prometheus.Counter
HeadersExchangeDuration prometheus.Histogram
}
func newMetrics() metrics {
subsystem := "libp2p"
return metrics{
CreatedConnectionCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "created_connection_count",
Help: "Number of initiated outgoing libp2p connections.",
}),
HandledConnectionCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "handled_connection_count",
Help: "Number of handled incoming libp2p connections.",
}),
CreatedStreamCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "created_stream_count",
Help: "Number of initiated outgoing libp2p streams.",
}),
ClosedStreamCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "closed_stream_count",
Help: "Number of closed outgoing libp2p streams.",
}),
StreamResetCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "stream_reset_count",
Help: "Number of outgoing libp2p streams resets.",
}),
HandledStreamCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "handled_stream_count",
Help: "Number of handled incoming libp2p streams.",
}),
BlocklistedPeerCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "blocklisted_peer_count",
Help: "Number of peers we've blocklisted.",
}),
BlocklistedPeerErrCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "blocklisted_peer_err_count",
Help: "Number of peers we've been unable to blocklist.",
}),
DisconnectCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "disconnect_count",
Help: "Number of peers we've disconnected from (initiated locally).",
}),
ConnectBreakerCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "connect_breaker_count",
Help: "Number of times we got a closed breaker while connecting to another peer.",
}),
UnexpectedProtocolReqCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "unexpected_protocol_request_count",
Help: "Number of requests the peer is not expecting.",
}),
KickedOutPeersCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "kickedout_peers_count",
Help: "Number of total kicked-out peers.",
}),
StreamHandlerErrResetCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "stream_handler_error_reset_count",
Help: "Number of total stream handler error resets.",
}),
HeadersExchangeDuration: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "headers_exchange_duration",
Help: "The duration spent exchanging the headers.",
}),
}
}
func (s *Service) Metrics() []prometheus.Collector {
return append(m.PrometheusCollectorsFromFields(s.metrics), s.handshakeService.Metrics()...)
}