From 45dec43967407c41c50aed7f912cef75c3f8cdce Mon Sep 17 00:00:00 2001 From: Gustavo Chain Date: Fri, 22 Apr 2022 10:55:56 +0200 Subject: [PATCH] Prevent sending key count when 0. Since the introduction of https://github.com/lightningnetwork/lnd/commit/afc53d1c52f457ba24dc2a82d0f78e87865113b5, 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. --- collectors/wallet_collector.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/collectors/wallet_collector.go b/collectors/wallet_collector.go index 67e9882..bf066ea 100644 --- a/collectors/wallet_collector.go +++ b/collectors/wallet_collector.go @@ -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", + ) + } } }