@@ -84,6 +84,14 @@ impl Metrics {
8484 }
8585 }
8686
87+ pub fn update_channels_count ( & self , is_closed : bool ) {
88+ if is_closed {
89+ self . total_channels_count . fetch_sub ( 1 , Ordering :: Relaxed ) ;
90+ } else {
91+ self . total_channels_count . fetch_add ( 1 , Ordering :: Relaxed ) ;
92+ }
93+ }
94+
8795 pub fn initialize_payment_metrics ( & self , node : & Node ) {
8896 let mut successful_payments_count = 0 ;
8997 let mut failed_payments_count = 0 ;
@@ -99,9 +107,14 @@ impl Metrics {
99107 self . total_successful_payments_count . store ( successful_payments_count, Ordering :: Relaxed ) ;
100108 self . total_failed_payments_count . store ( failed_payments_count, Ordering :: Relaxed ) ;
101109 self . total_pending_payments_count . store ( pending_payments_count, Ordering :: Relaxed ) ;
110+
111+ let channels_count = node. list_channels ( ) . len ( ) as i64 ;
112+ self . total_channels_count . store ( channels_count, Ordering :: Relaxed ) ;
113+
114+ self . update_all_balances ( node) ;
102115 }
103116
104- fn update_all_balances ( & self , node : & Node ) {
117+ pub fn update_all_balances ( & self , node : & Node ) {
105118 let all_balances = node. list_balances ( ) ;
106119 self . total_onchain_balance_sats
107120 . store ( all_balances. total_onchain_balance_sats , Ordering :: Relaxed ) ;
@@ -129,9 +142,6 @@ impl Metrics {
129142 . count ( ) as i64 ;
130143 self . total_pending_payments_count . store ( pending_payments_count, Ordering :: Relaxed ) ;
131144
132- let channels_count = all_channels. len ( ) as i64 ;
133- self . total_channels_count . store ( channels_count, Ordering :: Relaxed ) ;
134-
135145 let public_channels_count =
136146 all_channels. iter ( ) . filter ( |channel_details| channel_details. is_announced ) . count ( )
137147 as i64 ;
@@ -143,7 +153,6 @@ impl Metrics {
143153 self . total_private_channels_count . store ( private_channels_count, Ordering :: Relaxed ) ;
144154
145155 self . update_peer_count ( node) ;
146- self . update_all_balances ( node) ;
147156 }
148157
149158 /// Gathers all metrics and formats them into the Prometheus text-based format.
0 commit comments