Skip to content

Commit 2d45a88

Browse files
authored
autonatv2: add metrics (libp2p#3308)
1 parent b06bfec commit 2d45a88

File tree

13 files changed

+846
-51
lines changed

13 files changed

+846
-51
lines changed

dashboards/autonatv2/autonatv2.json

Lines changed: 234 additions & 27 deletions
Large diffs are not rendered by default.

dashboards/host-addrs/host-addrs.json

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": {
7+
"type": "grafana",
8+
"uid": "-- Grafana --"
9+
},
10+
"enable": true,
11+
"hide": true,
12+
"iconColor": "rgba(0, 211, 255, 1)",
13+
"name": "Annotations & Alerts",
14+
"type": "dashboard"
15+
}
16+
]
17+
},
18+
"editable": true,
19+
"fiscalYearStartMonth": 0,
20+
"graphTooltip": 0,
21+
"id": 16,
22+
"links": [],
23+
"panels": [
24+
{
25+
"datasource": {
26+
"type": "prometheus",
27+
"uid": "bdpgk86mw6jgga"
28+
},
29+
"fieldConfig": {
30+
"defaults": {
31+
"color": {
32+
"mode": "thresholds"
33+
},
34+
"mappings": [],
35+
"thresholds": {
36+
"mode": "absolute",
37+
"steps": [
38+
{
39+
"color": "green"
40+
},
41+
{
42+
"color": "red",
43+
"value": 80
44+
}
45+
]
46+
}
47+
},
48+
"overrides": []
49+
},
50+
"gridPos": {
51+
"h": 8,
52+
"w": 24,
53+
"x": 0,
54+
"y": 0
55+
},
56+
"id": 1,
57+
"options": {
58+
"colorMode": "value",
59+
"graphMode": "area",
60+
"justifyMode": "auto",
61+
"orientation": "auto",
62+
"percentChangeColorMode": "standard",
63+
"reduceOptions": {
64+
"calcs": [
65+
"lastNotNull"
66+
],
67+
"fields": "",
68+
"values": false
69+
},
70+
"showPercentChange": false,
71+
"textMode": "auto",
72+
"wideLayout": true
73+
},
74+
"pluginVersion": "11.6.1",
75+
"targets": [
76+
{
77+
"datasource": {
78+
"type": "prometheus",
79+
"uid": "bdpgk86mw6jgga"
80+
},
81+
"editorMode": "code",
82+
"expr": "libp2p_host_addrs_reachable{instance=~\"$instance\"}",
83+
"legendFormat": "{{instance}} {{ipv}}, {{transport}}",
84+
"range": true,
85+
"refId": "A"
86+
}
87+
],
88+
"title": "Reachable Addrs",
89+
"type": "stat"
90+
},
91+
{
92+
"datasource": {
93+
"type": "prometheus",
94+
"uid": "bdpgk86mw6jgga"
95+
},
96+
"fieldConfig": {
97+
"defaults": {
98+
"color": {
99+
"mode": "thresholds"
100+
},
101+
"mappings": [],
102+
"thresholds": {
103+
"mode": "absolute",
104+
"steps": [
105+
{
106+
"color": "green"
107+
},
108+
{
109+
"color": "red",
110+
"value": 80
111+
}
112+
]
113+
}
114+
},
115+
"overrides": []
116+
},
117+
"gridPos": {
118+
"h": 8,
119+
"w": 24,
120+
"x": 0,
121+
"y": 8
122+
},
123+
"id": 2,
124+
"options": {
125+
"colorMode": "value",
126+
"graphMode": "area",
127+
"justifyMode": "auto",
128+
"orientation": "auto",
129+
"percentChangeColorMode": "standard",
130+
"reduceOptions": {
131+
"calcs": [
132+
"lastNotNull"
133+
],
134+
"fields": "",
135+
"values": false
136+
},
137+
"showPercentChange": false,
138+
"textMode": "auto",
139+
"wideLayout": true
140+
},
141+
"pluginVersion": "11.6.1",
142+
"targets": [
143+
{
144+
"datasource": {
145+
"type": "prometheus",
146+
"uid": "bdpgk86mw6jgga"
147+
},
148+
"editorMode": "code",
149+
"expr": "libp2p_host_addrs_unreachable{instance=~\"$instance\"}",
150+
"legendFormat": "{{instance}} {{ipv}}, {{transport}}",
151+
"range": true,
152+
"refId": "A"
153+
}
154+
],
155+
"title": "Unreachable Addrs",
156+
"type": "stat"
157+
},
158+
{
159+
"datasource": {
160+
"type": "prometheus",
161+
"uid": "bdpgk86mw6jgga"
162+
},
163+
"fieldConfig": {
164+
"defaults": {
165+
"color": {
166+
"mode": "thresholds"
167+
},
168+
"mappings": [],
169+
"thresholds": {
170+
"mode": "absolute",
171+
"steps": [
172+
{
173+
"color": "green"
174+
},
175+
{
176+
"color": "red",
177+
"value": 80
178+
}
179+
]
180+
}
181+
},
182+
"overrides": []
183+
},
184+
"gridPos": {
185+
"h": 7,
186+
"w": 24,
187+
"x": 0,
188+
"y": 16
189+
},
190+
"id": 3,
191+
"options": {
192+
"colorMode": "value",
193+
"graphMode": "area",
194+
"justifyMode": "auto",
195+
"orientation": "auto",
196+
"percentChangeColorMode": "standard",
197+
"reduceOptions": {
198+
"calcs": [
199+
"lastNotNull"
200+
],
201+
"fields": "",
202+
"values": false
203+
},
204+
"showPercentChange": false,
205+
"textMode": "auto",
206+
"wideLayout": true
207+
},
208+
"pluginVersion": "11.6.1",
209+
"targets": [
210+
{
211+
"datasource": {
212+
"type": "prometheus",
213+
"uid": "bdpgk86mw6jgga"
214+
},
215+
"editorMode": "code",
216+
"expr": "libp2p_host_addrs_unknown{instance=~\"$instance\"}",
217+
"legendFormat": "{{instance}} {{ipv}}, {{transport}}",
218+
"range": true,
219+
"refId": "A"
220+
}
221+
],
222+
"title": "Unknown Reachability Addrs",
223+
"type": "stat"
224+
}
225+
],
226+
"preload": false,
227+
"schemaVersion": 41,
228+
"tags": [],
229+
"templating": {
230+
"list": [
231+
{
232+
"current": {
233+
"text": [
234+
"All"
235+
],
236+
"value": [
237+
"$__all"
238+
]
239+
},
240+
"definition": "label_values(up,instance)",
241+
"includeAll": true,
242+
"label": "instance",
243+
"multi": true,
244+
"name": "instance",
245+
"options": [],
246+
"query": {
247+
"qryType": 1,
248+
"query": "label_values(up,instance)",
249+
"refId": "PrometheusVariableQueryEditor-VariableQuery"
250+
},
251+
"refresh": 1,
252+
"regex": "",
253+
"type": "query"
254+
},
255+
{
256+
"current": {
257+
"text": "prometheus",
258+
"value": "bdpgk86mw6jgga"
259+
},
260+
"includeAll": false,
261+
"name": "data_source",
262+
"options": [],
263+
"query": "prometheus",
264+
"refresh": 1,
265+
"regex": "",
266+
"type": "datasource"
267+
}
268+
]
269+
},
270+
"time": {
271+
"from": "now-6h",
272+
"to": "now"
273+
},
274+
"timepicker": {},
275+
"timezone": "browser",
276+
"title": "go-libp2p Host Addresses",
277+
"uid": "beon8z59rh7nkf",
278+
"version": 5
279+
}

p2p/host/basic/addrs_manager.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/libp2p/go-netroute"
2121
ma "github.com/multiformats/go-multiaddr"
2222
manet "github.com/multiformats/go-multiaddr/net"
23+
"github.com/prometheus/client_golang/prometheus"
2324
)
2425

2526
const maxObservedAddrsPerListenAddr = 5
@@ -75,6 +76,8 @@ func newAddrsManager(
7576
observedAddrsManager observedAddrsManager,
7677
addrsUpdatedChan chan struct{},
7778
client autonatv2Client,
79+
enableMetrics bool,
80+
registerer prometheus.Registerer,
7881
) (*addrsManager, error) {
7982
ctx, cancel := context.WithCancel(context.Background())
8083
as := &addrsManager{
@@ -95,7 +98,11 @@ func newAddrsManager(
9598
as.hostReachability.Store(&unknownReachability)
9699

97100
if client != nil {
98-
as.addrsReachabilityTracker = newAddrsReachabilityTracker(client, as.triggerReachabilityUpdate, nil)
101+
var metricsTracker MetricsTracker
102+
if enableMetrics {
103+
metricsTracker = newMetricsTracker(withRegisterer(registerer))
104+
}
105+
as.addrsReachabilityTracker = newAddrsReachabilityTracker(client, as.triggerReachabilityUpdate, nil, metricsTracker)
99106
}
100107
return as, nil
101108
}

p2p/host/basic/addrs_manager_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/libp2p/go-libp2p/p2p/protocol/autonatv2"
1515
ma "github.com/multiformats/go-multiaddr"
1616
manet "github.com/multiformats/go-multiaddr/net"
17+
"github.com/prometheus/client_golang/prometheus"
1718
"github.com/stretchr/testify/assert"
1819
"github.com/stretchr/testify/require"
1920
)
@@ -194,7 +195,7 @@ func newAddrsManagerTestCase(t *testing.T, args addrsManagerArgs) addrsManagerTe
194195
}
195196
addrsUpdatedChan := make(chan struct{}, 1)
196197
am, err := newAddrsManager(
197-
eb, args.NATManager, args.AddrsFactory, args.ListenAddrs, nil, args.ObservedAddrsManager, addrsUpdatedChan, args.AutoNATClient,
198+
eb, args.NATManager, args.AddrsFactory, args.ListenAddrs, nil, args.ObservedAddrsManager, addrsUpdatedChan, args.AutoNATClient, true, prometheus.DefaultRegisterer,
198199
)
199200
require.NoError(t, err)
200201

0 commit comments

Comments
 (0)