Skip to content

Commit edbd824

Browse files
committed
feat: add metrics for LND tracker
Add gauges to monitor the LND tracker's internal state for better observability. - Track invoice queue length to monitor backlog size - Monitor count of active invoice trackers for capacity awareness - Conditionally compile metrics behind "metrics" feature flag
1 parent aaa9478 commit edbd824

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/fiber-lib/src/cch/trackers/lnd_trackers.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Actor for LndTrackerActor {
240240
message: Self::Msg,
241241
state: &mut Self::State,
242242
) -> Result<(), ActorProcessingErr> {
243-
match message {
243+
let res = match message {
244244
LndTrackerMessage::TrackInvoice(payment_hash) => {
245245
state.invoice_queue.push_back(payment_hash);
246246
state.process_invoice_queue(myself).await?;
@@ -278,7 +278,18 @@ impl Actor for LndTrackerActor {
278278
let _ = reply_port.send(snapshot);
279279
Ok(())
280280
}
281+
};
282+
283+
// update metrics
284+
#[cfg(feature = "metrics")]
285+
{
286+
metrics::gauge!(crate::metrics::CCH_LND_TRACKER_INVOICE_QUEUE_LEN)
287+
.set(state.invoice_queue.len() as f64);
288+
metrics::gauge!(crate::metrics::CCH_LND_TRACKER_ACTIVE_INVOICE_TRACKERS)
289+
.set(state.active_invoice_trackers as f64);
281290
}
291+
292+
res
282293
}
283294
}
284295

crates/fiber-lib/src/metrics.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ pub const INBOUND_PEER_COUNT: &str = "fiber.inbound_peer_count";
1010
pub const OUTBOUND_PEER_COUNT: &str = "fiber.outbound_peer_count";
1111
pub const DOWN_WITH_CHANNEL_PEER_COUNT: &str = "fiber.down_with_channel_peer_count";
1212

13+
pub const CCH_LND_TRACKER_INVOICE_QUEUE_LEN: &str = "fiber.cch.lnd_tracker.invoice_queue_len";
14+
pub const CCH_LND_TRACKER_ACTIVE_INVOICE_TRACKERS: &str =
15+
"fiber.cch.lnd_tracker.active_invoice_trackers";
16+
1317
pub fn start_metrics(metrics_addr: &str) -> Result<(), Box<dyn std::error::Error>> {
1418
let socket_addr = metrics_addr
1519
.to_socket_addrs()

0 commit comments

Comments
 (0)