Skip to content

Commit 45dec43

Browse files
committed
Prevent sending key count when 0.
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.
1 parent a1fa10f commit 45dec43

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

collectors/wallet_collector.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,21 @@ func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
198198
path := account.GetDerivationPath()
199199

200200
// internal key count.
201-
ch <- prometheus.MustNewConstMetric(
202-
u.keyCountDesc, prometheus.CounterValue,
203-
float64(account.InternalKeyCount),
204-
name, addrType, path, "internal",
205-
)
201+
if account.InternalKeyCount > 0 {
202+
ch <- prometheus.MustNewConstMetric(
203+
u.keyCountDesc, prometheus.CounterValue,
204+
float64(account.InternalKeyCount),
205+
name, addrType, path, "internal",
206+
)
207+
}
206208

207209
// external key count.
208-
ch <- prometheus.MustNewConstMetric(
209-
u.keyCountDesc, prometheus.CounterValue,
210-
float64(account.ExternalKeyCount),
211-
name, addrType, path, "external",
212-
)
210+
if account.ExternalKeyCount > 0 {
211+
ch <- prometheus.MustNewConstMetric(
212+
u.keyCountDesc, prometheus.CounterValue,
213+
float64(account.ExternalKeyCount),
214+
name, addrType, path, "external",
215+
)
216+
}
213217
}
214218
}

0 commit comments

Comments
 (0)