@@ -75,12 +75,12 @@ func NewChannelsCollector(lnd lndclient.LightningClient, errChan chan<- error,
7575 pendingForceCloseBalanceDesc : prometheus .NewDesc (
7676 "lnd_channels_pending_force_close_balance_sat" ,
7777 "force closed channel balances in satoshis" ,
78- append ( labels , "blocks_until_maturity" ) , nil ,
78+ [] string { "status" } , nil ,
7979 ),
8080 waitingCloseBalanceDesc : prometheus .NewDesc (
8181 "lnd_channels_waiting_close_balance_sat" ,
8282 "waiting to close channel balances in satoshis" ,
83- labels , nil ,
83+ nil , nil ,
8484 ),
8585 incomingChanSatDesc : prometheus .NewDesc (
8686 "lnd_channels_bandwidth_incoming_sat" ,
@@ -408,32 +408,33 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
408408 "waiting_close" ,
409409 )
410410
411+ // Preinitialize the map with all possible anchor state labels to avoid
412+ // "stuck" values when selecting a longer time range.
413+ forceCloseTotal := map [string ]btcutil.Amount {
414+ anchorStateToString (lndclient .ForceCloseAnchorStateLimbo ): 0 ,
415+ anchorStateToString (lndclient .ForceCloseAnchorStateRecovered ): 0 ,
416+ anchorStateToString (lndclient .ForceCloseAnchorStateLost ): 0 ,
417+ }
411418 for _ , forceClose := range pendingChannelsResp .PendingForceClose {
412- // Labels are: "chan_id", "status", "initiator", "peer",
413- // "blocks_until_maturity". We'll use status to hold the anchor
414- // state.
419+ forceCloseTotal [anchorStateToString (forceClose .AnchorState )] +=
420+ forceClose .RecoveredBalance
421+ }
422+
423+ for anchorState , balance := range forceCloseTotal {
415424 ch <- prometheus .MustNewConstMetric (
416425 c .pendingForceCloseBalanceDesc , prometheus .GaugeValue ,
417- float64 (forceClose .RecoveredBalance ),
418- forceClose .ChannelPoint .String (),
419- anchorStateToString (forceClose .AnchorState ),
420- forceClose .ChannelInitiator .String (),
421- forceClose .PubKeyBytes .String (),
422- fmt .Sprintf ("%d" , forceClose .BlocksUntilMaturity ),
426+ float64 (balance ), anchorState ,
423427 )
424428 }
425429
430+ var waitingClosetotal btcutil.Amount
426431 for _ , waitingClose := range pendingChannelsResp .WaitingClose {
427- // Labels are: "chan_id", "status", "initiator", "peer".
428- ch <- prometheus .MustNewConstMetric (
429- c .waitingCloseBalanceDesc , prometheus .GaugeValue ,
430- float64 (waitingClose .LocalBalance ),
431- waitingClose .ChannelPoint .String (),
432- waitingClose .ChanStatusFlags ,
433- waitingClose .ChannelInitiator .String (),
434- waitingClose .PubKeyBytes .String (),
435- )
432+ waitingClosetotal += waitingClose .LocalBalance
436433 }
434+ ch <- prometheus .MustNewConstMetric (
435+ c .waitingCloseBalanceDesc , prometheus .GaugeValue ,
436+ float64 (waitingClosetotal ),
437+ )
437438
438439 // Get the list of closed channels.
439440 closedChannelsResp , err := c .lnd .ClosedChannels (context .Background ())
0 commit comments