@@ -30,6 +30,10 @@ type WalletCollector struct {
3030 confirmedBalanceDesc * prometheus.Desc
3131 unconfirmedBalanceDesc * prometheus.Desc
3232
33+ // We'll use one counter to keep track of both internal and external key
34+ // count.
35+ keyCountDesc * prometheus.Desc
36+
3337 // errChan is a channel that we send any errors that we encounter into.
3438 // This channel should be buffered so that it does not block sends.
3539 errChan chan <- error
@@ -71,6 +75,16 @@ func NewWalletCollector(lnd *lndclient.LndServices,
7175 "unconfirmed wallet balance" ,
7276 nil , nil ,
7377 ),
78+ keyCountDesc : prometheus .NewDesc (
79+ "lnd_wallet_key_count" , "wallet key count" ,
80+ []string {
81+ "account_name" ,
82+ "address_type" ,
83+ "derivation_path" ,
84+ "key_type" ,
85+ }, nil ,
86+ ),
87+
7488 errChan : errChan ,
7589 }
7690}
@@ -88,6 +102,7 @@ func (u *WalletCollector) Describe(ch chan<- *prometheus.Desc) {
88102 ch <- u .avgUtxoSizeDesc
89103 ch <- u .confirmedBalanceDesc
90104 ch <- u .unconfirmedBalanceDesc
105+ ch <- u .keyCountDesc
91106}
92107
93108// Collect is called by the Prometheus registry when collecting metrics.
@@ -169,4 +184,31 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
169184 u .unconfirmedBalanceDesc , prometheus .GaugeValue ,
170185 float64 (walletBal .Unconfirmed ),
171186 )
187+
188+ accounts , err := u .lnd .WalletKit .ListAccounts (context .Background (), "" , 0 )
189+ if err != nil {
190+ u .errChan <- fmt .Errorf ("WalletCollector ListAccounts" +
191+ "failed with: %v" , err )
192+ return
193+ }
194+
195+ for _ , account := range accounts {
196+ name := account .GetName ()
197+ addrType := account .GetAddressType ().String ()
198+ path := account .GetDerivationPath ()
199+
200+ // internal key count.
201+ ch <- prometheus .MustNewConstMetric (
202+ u .keyCountDesc , prometheus .CounterValue ,
203+ float64 (account .InternalKeyCount ),
204+ name , addrType , path , "internal" ,
205+ )
206+
207+ // external key count.
208+ ch <- prometheus .MustNewConstMetric (
209+ u .keyCountDesc , prometheus .CounterValue ,
210+ float64 (account .ExternalKeyCount ),
211+ name , addrType , path , "external" ,
212+ )
213+ }
172214}
0 commit comments