Skip to content

Commit 773fe66

Browse files
feat(metrics): add utreexo peer count metric
1 parent 9052256 commit 773fe66

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

crates/floresta-wire/src/p2p_wire/node/sync_ctx.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ where
162162
.and_then(|p| p.channel.send(NodeRequest::Shutdown).ok());
163163
}
164164

165+
#[cfg(feature = "metrics")]
166+
{
167+
use metrics::get_metrics;
168+
get_metrics().utreexo_peer_count.set(utreexo_peers as f64);
169+
}
170+
165171
if utreexo_peers < 2 {
166172
info!("Not enough utreexo peers (we have {utreexo_peers}), opening a new connection");
167173
self.maybe_open_connection(service_flags::UTREEXO.into())?;

metrics/grafana/dashboards/floresta-dashboard.json

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,46 @@
156156
"overrides": []
157157
}
158158
},
159+
{
160+
"type": "stat",
161+
"title": "Utreexo Peer Count",
162+
"description": "Number of peers that support the Utreexo protocol. At least 2 are required for block download.",
163+
"id": 13,
164+
"datasource": { "type": "prometheus", "uid": "${datasource}" },
165+
"gridPos": { "h": 3, "w": 24, "x": 0, "y": 7 },
166+
"options": {
167+
"reduceOptions": { "calcs": ["lastNotNull"], "fields": "", "values": false },
168+
"orientation": "horizontal",
169+
"textMode": "auto",
170+
"colorMode": "background",
171+
"graphMode": "none",
172+
"justifyMode": "center"
173+
},
174+
"targets": [
175+
{ "expr": "max(utreexo_peer_count{instance=~\"$instance\"})", "legendFormat": "utreexo peers", "refId": "A" }
176+
],
177+
"fieldConfig": {
178+
"defaults": {
179+
"unit": "short",
180+
"decimals": 0,
181+
"thresholds": {
182+
"mode": "absolute",
183+
"steps": [
184+
{ "color": "red", "value": null },
185+
{ "color": "yellow", "value": 1 },
186+
{ "color": "green", "value": 2 }
187+
]
188+
},
189+
"color": { "mode": "thresholds" }
190+
},
191+
"overrides": []
192+
}
193+
},
159194
{
160195
"type": "row",
161196
"title": "Network",
162197
"id": 101,
163-
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 7 },
198+
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 10 },
164199
"collapsed": false
165200
},
166201
{

metrics/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct AppMetrics {
1717
pub memory_usage: Gauge<f64, AtomicU64>,
1818
pub block_height: Gauge,
1919
pub peer_count: Gauge<f64, AtomicU64>,
20+
pub utreexo_peer_count: Gauge<f64, AtomicU64>,
2021
pub avg_block_processing_time: Gauge<f64, AtomicU64>,
2122
pub message_times: Histogram,
2223
}
@@ -27,6 +28,7 @@ impl AppMetrics {
2728
let memory_usage = Gauge::<f64, AtomicU64>::default();
2829
let block_height = Gauge::default();
2930
let peer_count = Gauge::<f64, AtomicU64>::default();
31+
let utreexo_peer_count = Gauge::<f64, AtomicU64>::default();
3032
let avg_block_processing_time = Gauge::<f64, AtomicU64>::default();
3133
let message_times = Histogram::new([0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 30.0].into_iter());
3234

@@ -36,6 +38,11 @@ impl AppMetrics {
3638
"Number of connected peers",
3739
peer_count.clone(),
3840
);
41+
registry.register(
42+
"utreexo_peer_count",
43+
"Number of connected utreexo peers",
44+
utreexo_peer_count.clone(),
45+
);
3946

4047
registry.register(
4148
"avg_block_processing_time",
@@ -60,6 +67,7 @@ impl AppMetrics {
6067
block_height,
6168
memory_usage,
6269
peer_count,
70+
utreexo_peer_count,
6371
avg_block_processing_time,
6472
message_times,
6573
}

0 commit comments

Comments
 (0)