@@ -30,6 +30,11 @@ type WalletCollector struct {
30
30
confirmedBalanceDesc * prometheus.Desc
31
31
unconfirmedBalanceDesc * prometheus.Desc
32
32
33
+ // We'll use one gauge to keep track of both internal and external key
34
+ // count.
35
+ keyCountDesc * prometheus.Desc
36
+
37
+ // We'll use two gauges to keep track of the accounts internal and external
33
38
// errChan is a channel that we send any errors that we encounter into.
34
39
// This channel should be buffered so that it does not block sends.
35
40
errChan chan <- error
@@ -39,6 +44,8 @@ type WalletCollector struct {
39
44
func NewWalletCollector (lnd * lndclient.LndServices ,
40
45
errChan chan <- error ) * WalletCollector {
41
46
47
+ // these labels are specific for key_count metrics
48
+ keyCountLabels := []string {"account_name" , "address_type" , "derivation_path" , "key_type" }
42
49
return & WalletCollector {
43
50
lnd : lnd ,
44
51
numUtxosConfDesc : prometheus .NewDesc (
@@ -71,6 +78,12 @@ func NewWalletCollector(lnd *lndclient.LndServices,
71
78
"unconfirmed wallet balance" ,
72
79
nil , nil ,
73
80
),
81
+ keyCountDesc : prometheus .NewDesc (
82
+ "lnd_wallet_key_count" ,
83
+ "wallet key count" ,
84
+ keyCountLabels , nil ,
85
+ ),
86
+
74
87
errChan : errChan ,
75
88
}
76
89
}
@@ -88,6 +101,7 @@ func (u *WalletCollector) Describe(ch chan<- *prometheus.Desc) {
88
101
ch <- u .avgUtxoSizeDesc
89
102
ch <- u .confirmedBalanceDesc
90
103
ch <- u .unconfirmedBalanceDesc
104
+ ch <- u .keyCountDesc
91
105
}
92
106
93
107
// Collect is called by the Prometheus registry when collecting metrics.
@@ -169,4 +183,30 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
169
183
u .unconfirmedBalanceDesc , prometheus .GaugeValue ,
170
184
float64 (walletBal .Unconfirmed ),
171
185
)
186
+
187
+ accounts , err := u .lnd .WalletKit .ListAccounts (context .Background (), "" , 0 )
188
+ if err != nil {
189
+ u .errChan <- fmt .Errorf ("WalletCollector ListAccounts" +
190
+ "failed with: %v" , err )
191
+ return
192
+ }
193
+
194
+ for _ , account := range accounts {
195
+ name , addrType , path := account .GetName (),
196
+ account .GetAddressType ().String (), account .GetDerivationPath ()
197
+
198
+ // internal key count.
199
+ ch <- prometheus .MustNewConstMetric (
200
+ u .keyCountDesc , prometheus .CounterValue ,
201
+ float64 (account .InternalKeyCount ),
202
+ name , addrType , path , "internal" ,
203
+ )
204
+
205
+ // external key count.
206
+ ch <- prometheus .MustNewConstMetric (
207
+ u .keyCountDesc , prometheus .CounterValue ,
208
+ float64 (account .ExternalKeyCount ),
209
+ name , addrType , path , "external" ,
210
+ )
211
+ }
172
212
}
0 commit comments