Skip to content

Commit a1fa10f

Browse files
authored
Merge pull request #76 from bottlepay/wallet_key_count
Add wallet_key_count metric
2 parents 4500c23 + b81c950 commit a1fa10f

File tree

5 files changed

+699
-123
lines changed

5 files changed

+699
-123
lines changed

collectors/channels_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
246246

247247
// Next, for each channel we'll export the total sum of our balances,
248248
// as well as the number of pending HTLCs.
249-
listChannelsResp, err := c.lnd.ListChannels(context.Background())
249+
listChannelsResp, err := c.lnd.ListChannels(context.Background(), false, false)
250250
if err != nil {
251251
c.errChan <- fmt.Errorf("ChannelsCollector ListChannels "+
252252
"failed with: %v", err)
@@ -557,7 +557,7 @@ func (c *ChannelsCollector) getRemotePolicies(pubkey route.Vertex) (
557557
// Only record policies for peers that have this channel
558558
// enabled.
559559
if policy != nil && !policy.Disabled {
560-
policies[i.ChannelId] = policy
560+
policies[i.ChannelID] = policy
561561
}
562562
}
563563

collectors/wallet_collector.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

go.mod

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ module github.com/lightninglabs/lndmon
22

33
require (
44
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
5-
github.com/btcsuite/btcutil v1.0.2
6-
github.com/google/go-cmp v0.3.1 // indirect
5+
github.com/btcsuite/btcutil v1.0.3-0.20210527170813-e2ba6805a890
6+
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
77
github.com/jessevdk/go-flags v1.4.0
88
github.com/jrick/logrotate v1.0.0
9-
github.com/lightninglabs/lndclient v0.11.0-4.0.20201117105441-b9a8c8f4910a
10-
github.com/lightningnetwork/lnd v0.11.1-beta
11-
github.com/prometheus/client_golang v0.9.3
12-
github.com/stretchr/testify v1.5.1
13-
golang.org/x/text v0.3.2 // indirect
9+
github.com/lightninglabs/lndclient v0.13.0-10
10+
github.com/lightningnetwork/lnd v0.13.0-beta.rc5.0.20210920062527-d9f0f07142ea
11+
github.com/prometheus/client_golang v1.11.0
12+
github.com/stretchr/testify v1.7.0
1413
)
1514

1615
go 1.15

0 commit comments

Comments
 (0)