Skip to content

Commit abad0ac

Browse files
collectors: distinguish attempts by payment status
Add a label to the metric for tracking htlc attempts so that we can differentiate between attempts made as part of payments that are successfull from attempts for payments which fail. This allows you to answer questions like: How many attempts does a successful payment take on average?
1 parent 7b1000e commit abad0ac

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

collectors/payments_collector.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ var (
2323
[]string{"status"},
2424
)
2525

26-
// totalHTLCAttempts is a simple counter which, in combination with the
27-
// payment counter, permits tracking the number of attempts per payment.
28-
totalHTLCAttempts = prometheus.NewCounter(
26+
// totalHTLCAttempts tracks the number of HTLC attempts made based on
27+
// the payment status (success or fail). When combined with the payment
28+
// counter, this permits tracking the number of attempts per payment.
29+
totalHTLCAttempts = prometheus.NewCounterVec(
2930
prometheus.CounterOpts{
3031
Name: "lnd_total_htlc_attempts",
31-
Help: "Total number of HTLC attempts across all payments",
32+
Help: "Total number of HTLC attempts across all payments, labeled by final payment status",
3233
},
34+
[]string{"status"},
3335
)
3436

3537
// paymentAttempts is a histogram for visualizing what portion of
@@ -164,12 +166,13 @@ func processPaymentUpdate(payment *lnrpc.Payment) {
164166
status = "unknown"
165167
}
166168

169+
// Increment metrics with proper label.
167170
totalPayments.WithLabelValues(status).Inc()
171+
168172
attemptCount := len(payment.Htlcs)
173+
totalHTLCAttempts.WithLabelValues(status).Add(float64(attemptCount))
169174

170-
totalHTLCAttempts.Add(float64(attemptCount))
171175
paymentAttempts.Observe(float64(attemptCount))
172-
173176
paymentLogger.Debugf("Payment %s updated: status=%s, %d attempts",
174177
payment.PaymentHash, status, attemptCount)
175178
}

0 commit comments

Comments
 (0)