Skip to content

Commit

Permalink
Prevent sending key count when 0.
Browse files Browse the repository at this point in the history
Since the introduction of
lightningnetwork/lnd@afc53d1,
lnd will create 255 new wallets. Those might never be used but metrics
are being sent, polluting the metric space.

This PR only send metrics when keycount is > 0 on both internal and
external branches.
  • Loading branch information
qustavo committed Apr 22, 2022
1 parent a1fa10f commit 45dec43
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions collectors/wallet_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,21 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
path := account.GetDerivationPath()

// internal key count.
ch <- prometheus.MustNewConstMetric(
u.keyCountDesc, prometheus.CounterValue,
float64(account.InternalKeyCount),
name, addrType, path, "internal",
)
if account.InternalKeyCount > 0 {
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",
)
if account.ExternalKeyCount > 0 {
ch <- prometheus.MustNewConstMetric(
u.keyCountDesc, prometheus.CounterValue,
float64(account.ExternalKeyCount),
name, addrType, path, "external",
)
}
}
}

0 comments on commit 45dec43

Please sign in to comment.