Skip to content

Commit

Permalink
Merge pull request #76 from bottlepay/wallet_key_count
Browse files Browse the repository at this point in the history
Add wallet_key_count metric
  • Loading branch information
carlaKC authored Jan 12, 2022
2 parents 4500c23 + b81c950 commit a1fa10f
Show file tree
Hide file tree
Showing 5 changed files with 699 additions and 123 deletions.
4 changes: 2 additions & 2 deletions collectors/channels_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {

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

Expand Down
42 changes: 42 additions & 0 deletions collectors/wallet_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type WalletCollector struct {
confirmedBalanceDesc *prometheus.Desc
unconfirmedBalanceDesc *prometheus.Desc

// We'll use one counter to keep track of both internal and external key
// count.
keyCountDesc *prometheus.Desc

// errChan is a channel that we send any errors that we encounter into.
// This channel should be buffered so that it does not block sends.
errChan chan<- error
Expand Down Expand Up @@ -71,6 +75,16 @@ func NewWalletCollector(lnd *lndclient.LndServices,
"unconfirmed wallet balance",
nil, nil,
),
keyCountDesc: prometheus.NewDesc(
"lnd_wallet_key_count", "wallet key count",
[]string{
"account_name",
"address_type",
"derivation_path",
"key_type",
}, nil,
),

errChan: errChan,
}
}
Expand All @@ -88,6 +102,7 @@ func (u *WalletCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- u.avgUtxoSizeDesc
ch <- u.confirmedBalanceDesc
ch <- u.unconfirmedBalanceDesc
ch <- u.keyCountDesc
}

// Collect is called by the Prometheus registry when collecting metrics.
Expand Down Expand Up @@ -169,4 +184,31 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
u.unconfirmedBalanceDesc, prometheus.GaugeValue,
float64(walletBal.Unconfirmed),
)

accounts, err := u.lnd.WalletKit.ListAccounts(context.Background(), "", 0)
if err != nil {
u.errChan <- fmt.Errorf("WalletCollector ListAccounts"+
"failed with: %v", err)
return
}

for _, account := range accounts {
name := account.GetName()
addrType := account.GetAddressType().String()
path := account.GetDerivationPath()

// internal key count.
ch <- prometheus.MustNewConstMetric(
u.keyCountDesc, prometheus.CounterValue,
float64(account.InternalKeyCount),
name, addrType, path, "internal",
)

// external key count.
ch <- prometheus.MustNewConstMetric(
u.keyCountDesc, prometheus.CounterValue,
float64(account.ExternalKeyCount),
name, addrType, path, "external",
)
}
}
13 changes: 6 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ module github.com/lightninglabs/lndmon

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

go 1.15
Loading

0 comments on commit a1fa10f

Please sign in to comment.