-
Notifications
You must be signed in to change notification settings - Fork 338
/
metrics.go
187 lines (181 loc) · 6.96 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright 2021 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 kademlia
import (
m "github.com/ethersphere/bee/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
// metrics groups kademlia related prometheus counters.
type metrics struct {
PickCalls prometheus.Counter
PickCallsFalse prometheus.Counter
CurrentDepth prometheus.Gauge
CurrentStorageDepth prometheus.Gauge
CurrentlyKnownPeers prometheus.Gauge
CurrentlyConnectedPeers prometheus.Gauge
InternalMetricsFlushTime prometheus.Histogram
InternalMetricsFlushTotalErrors prometheus.Counter
TotalBeforeExpireWaits prometheus.Counter
TotalInboundConnections prometheus.Counter
TotalInboundDisconnections prometheus.Counter
TotalOutboundConnections prometheus.Counter
TotalOutboundConnectionAttempts prometheus.Counter
TotalOutboundConnectionFailedAttempts prometheus.Counter
TotalBootNodesConnectionAttempts prometheus.Counter
StartAddAddressBookOverlaysTime prometheus.Histogram
PeerLatencyEWMA prometheus.Histogram
Flag prometheus.Counter
Unflag prometheus.Counter
Blocklist prometheus.Counter
ReachabilityStatus *prometheus.GaugeVec
PeersReachabilityStatus *prometheus.GaugeVec
}
// newMetrics is a convenient constructor for creating new metrics.
func newMetrics() metrics {
const subsystem = "kademlia"
return metrics{
PickCalls: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "pick_calls",
Help: "The number of pick method call made.",
}),
PickCallsFalse: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "pick_calls_false",
Help: "The number of pick method call made which returned false.",
}),
CurrentDepth: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "current_depth",
Help: "The current value of depth.",
}),
CurrentStorageDepth: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "current_storage_depth",
Help: "The current value of storage depth.",
}),
CurrentlyKnownPeers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "currently_known_peers",
Help: "Number of currently known peers.",
}),
CurrentlyConnectedPeers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "currently_connected_peers",
Help: "Number of currently connected peers.",
}),
InternalMetricsFlushTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "internal_metrics_flush_time",
Help: "The time spent flushing the internal metrics about peers to the state-store.",
}),
InternalMetricsFlushTotalErrors: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "internal_metrics_flush_total_errors",
Help: "Number of total errors occurred during flushing the internal metrics to the state-store.",
}),
TotalBeforeExpireWaits: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_before_expire_waits",
Help: "Total before expire waits made.",
}),
TotalInboundConnections: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_inbound_connections",
Help: "Total inbound connections made.",
}),
TotalInboundDisconnections: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_inbound_disconnections",
Help: "Total inbound disconnections made.",
}),
TotalOutboundConnections: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_outbound_connections",
Help: "Total outbound connections made.",
}),
TotalOutboundConnectionAttempts: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_outbound_connection_attempts",
Help: "Total outbound connection attempts made.",
}),
TotalOutboundConnectionFailedAttempts: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_outbound_connection_failed_attempts",
Help: "Total outbound connection failed attempts made.",
}),
TotalBootNodesConnectionAttempts: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_bootnodes_connection_attempts",
Help: "Total boot-nodes connection attempts made.",
}),
StartAddAddressBookOverlaysTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "start_add_addressbook_overlays_time",
Help: "The time spent adding overlays peers from addressbook on kademlia start.",
}),
PeerLatencyEWMA: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "peer_latency_ewma",
Help: "Peer latency EWMA value distribution.",
}),
Flag: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "flag",
Help: "The nubmer of times peers have been flagged.",
}),
Unflag: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "unflag",
Help: "The nubmer of times peers have been unflagged.",
}),
Blocklist: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "blocklist",
Help: "The nubmer of times peers have been blocklisted.",
}),
ReachabilityStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "reachability_status",
Help: "The reachability status of the node.",
},
[]string{"reachability_status"},
),
PeersReachabilityStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "peers_reachability_status",
Help: "The reachability status of peers.",
},
[]string{"peers_reachability_status"},
),
}
}
// Metrics returns set of prometheus collectors.
func (k *Kad) Metrics() []prometheus.Collector {
return m.PrometheusCollectorsFromFields(k.metrics)
}