-
Notifications
You must be signed in to change notification settings - Fork 50
Add wallet_key_count metric #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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, | ||
} | ||
} | ||
|
@@ -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. | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: wrap at 80 chars There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't it already below 80? (vim shows :78) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mine shows 83. Is your tab size set to 8 spaces? |
||
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", | ||
) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.