Skip to content

Commit 5beeb77

Browse files
collectors: export all collectors
1 parent 6465636 commit 5beeb77

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

collectors/chain_collector.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ import (
77
"github.com/prometheus/client_golang/prometheus"
88
)
99

10-
// chainCollector is a collector that keeps track of on-chain information.
11-
type chainCollector struct {
10+
// ChainCollector is a collector that keeps track of on-chain information.
11+
type ChainCollector struct {
1212
bestBlockHeight *prometheus.Desc
1313
bestBlockTimestamp *prometheus.Desc
1414

1515
lnd lnrpc.LightningClient
1616
}
1717

18-
// newChainCollector returns a new instance of the chainCollector for the target
18+
// NewChainCollector returns a new instance of the ChainCollector for the target
1919
// lnd client.
20-
func newChainCollector(lnd lnrpc.LightningClient) *chainCollector {
21-
return &chainCollector{
20+
func NewChainCollector(lnd lnrpc.LightningClient) *ChainCollector {
21+
return &ChainCollector{
2222
bestBlockHeight: prometheus.NewDesc(
2323
"lnd_chain_block_height", "best block height from lnd",
2424
nil, nil,
@@ -37,15 +37,15 @@ func newChainCollector(lnd lnrpc.LightningClient) *chainCollector {
3737
// last descriptor has been sent.
3838
//
3939
// NOTE: Part of the prometheus.Collector interface.
40-
func (c *chainCollector) Describe(ch chan<- *prometheus.Desc) {
40+
func (c *ChainCollector) Describe(ch chan<- *prometheus.Desc) {
4141
ch <- c.bestBlockHeight
4242
ch <- c.bestBlockTimestamp
4343
}
4444

4545
// Collect is called by the Prometheus registry when collecting metrics.
4646
//
4747
// NOTE: Part of the prometheus.Collector interface.
48-
func (c *chainCollector) Collect(ch chan<- prometheus.Metric) {
48+
func (c *ChainCollector) Collect(ch chan<- prometheus.Metric) {
4949
resp, err := c.lnd.GetInfo(context.Background(), &lnrpc.GetInfoRequest{})
5050
if err != nil {
5151
chainLogger.Error(err)
@@ -66,7 +66,7 @@ func (c *chainCollector) Collect(ch chan<- prometheus.Metric) {
6666
func init() {
6767
metricsMtx.Lock()
6868
collectors["chain"] = func(lnd lnrpc.LightningClient) prometheus.Collector {
69-
return newChainCollector(lnd)
69+
return NewChainCollector(lnd)
7070
}
7171
metricsMtx.Unlock()
7272
}

collectors/channels_collector.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/prometheus/client_golang/prometheus"
99
)
1010

11-
// channelsCollector is a collector that keeps track of channel infromation.
12-
type channelsCollector struct {
11+
// ChannelsCollector is a collector that keeps track of channel infromation.
12+
type ChannelsCollector struct {
1313
channelBalanceDesc *prometheus.Desc
1414
pendingChannelBalanceDesc *prometheus.Desc
1515

@@ -35,11 +35,11 @@ type channelsCollector struct {
3535
lnd lnrpc.LightningClient
3636
}
3737

38-
// newChannelsCollector returns a new instance of the channelsCollector for the
38+
// NewChannelsCollector returns a new instance of the ChannelsCollector for the
3939
// target lnd client.
40-
func newChannelsCollector(lnd lnrpc.LightningClient) *channelsCollector {
40+
func NewChannelsCollector(lnd lnrpc.LightningClient) *ChannelsCollector {
4141
labels := []string{"chan_id"}
42-
return &channelsCollector{
42+
return &ChannelsCollector{
4343
channelBalanceDesc: prometheus.NewDesc(
4444
"lnd_channels_open_balance_sat",
4545
"total balance of channels in satoshis",
@@ -135,7 +135,7 @@ func newChannelsCollector(lnd lnrpc.LightningClient) *channelsCollector {
135135
// last descriptor has been sent.
136136
//
137137
// NOTE: Part of the prometheus.Collector interface.
138-
func (c *channelsCollector) Describe(ch chan<- *prometheus.Desc) {
138+
func (c *ChannelsCollector) Describe(ch chan<- *prometheus.Desc) {
139139
ch <- c.channelBalanceDesc
140140
ch <- c.pendingChannelBalanceDesc
141141

@@ -164,7 +164,7 @@ func (c *channelsCollector) Describe(ch chan<- *prometheus.Desc) {
164164
// Collect is called by the Prometheus registry when collecting metrics.
165165
//
166166
// NOTE: Part of the prometheus.Collector interface.
167-
func (c *channelsCollector) Collect(ch chan<- prometheus.Metric) {
167+
func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
168168
// First, based on the channel balance, we'll export the total and
169169
// pending channel balances.
170170
chanBalResp, err := c.lnd.ChannelBalance(
@@ -279,7 +279,7 @@ func (c *channelsCollector) Collect(ch chan<- prometheus.Metric) {
279279
func init() {
280280
metricsMtx.Lock()
281281
collectors["channels"] = func(lnd lnrpc.LightningClient) prometheus.Collector {
282-
return newChannelsCollector(lnd)
282+
return NewChannelsCollector(lnd)
283283
}
284284
metricsMtx.Unlock()
285285
}

collectors/graph_collector.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/prometheus/client_golang/prometheus"
99
)
1010

11-
// graphCollector is a collector that keeps track of graph information.
12-
type graphCollector struct {
11+
// GraphCollector is a collector that keeps track of graph information.
12+
type GraphCollector struct {
1313
numEdgesDesc *prometheus.Desc
1414
numNodesDesc *prometheus.Desc
1515

@@ -22,11 +22,11 @@ type graphCollector struct {
2222
lnd lnrpc.LightningClient
2323
}
2424

25-
// newGraphCollector returns a new instance of the graphCollector for the target
25+
// NewGraphCollector returns a new instance of the GraphCollector for the target
2626
// lnd client.
27-
func newGraphCollector(lnd lnrpc.LightningClient) *graphCollector {
27+
func NewGraphCollector(lnd lnrpc.LightningClient) *GraphCollector {
2828
labels := []string{"chan_id", "pubkey"}
29-
return &graphCollector{
29+
return &GraphCollector{
3030
numEdgesDesc: prometheus.NewDesc(
3131
"lnd_graph_edges_count",
3232
"total number of edges in the graph",
@@ -73,7 +73,7 @@ func newGraphCollector(lnd lnrpc.LightningClient) *graphCollector {
7373
// last descriptor has been sent.
7474
//
7575
// NOTE: Part of the prometheus.Collector interface.
76-
func (g *graphCollector) Describe(ch chan<- *prometheus.Desc) {
76+
func (g *GraphCollector) Describe(ch chan<- *prometheus.Desc) {
7777
ch <- g.numEdgesDesc
7878
ch <- g.numNodesDesc
7979

@@ -87,7 +87,7 @@ func (g *graphCollector) Describe(ch chan<- *prometheus.Desc) {
8787
// Collect is called by the Prometheus registry when collecting metrics.
8888
//
8989
// NOTE: Part of the prometheus.Collector interface.
90-
func (g *graphCollector) Collect(ch chan<- prometheus.Metric) {
90+
func (g *GraphCollector) Collect(ch chan<- prometheus.Metric) {
9191
resp, err := g.lnd.DescribeGraph(
9292
context.Background(), &lnrpc.ChannelGraphRequest{},
9393
)
@@ -111,7 +111,7 @@ func (g *graphCollector) Collect(ch chan<- prometheus.Metric) {
111111
}
112112
}
113113

114-
func (g *graphCollector) collectRoutingPolicyMetrics(
114+
func (g *GraphCollector) collectRoutingPolicyMetrics(
115115
ch chan<- prometheus.Metric, edge *lnrpc.ChannelEdge) {
116116

117117
pubkeys := []string{edge.Node1Pub, edge.Node2Pub}
@@ -152,7 +152,7 @@ func (g *graphCollector) collectRoutingPolicyMetrics(
152152
func init() {
153153
metricsMtx.Lock()
154154
collectors["graph"] = func(lnd lnrpc.LightningClient) prometheus.Collector {
155-
return newGraphCollector(lnd)
155+
return NewGraphCollector(lnd)
156156
}
157157
metricsMtx.Unlock()
158158
}

collectors/peer_collector.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/prometheus/client_golang/prometheus"
88
)
99

10-
// peerCollector is a collector that keeps track of peer information.
11-
type peerCollector struct {
10+
// PeerCollector is a collector that keeps track of peer information.
11+
type PeerCollector struct {
1212
peerCountDesc *prometheus.Desc
1313

1414
pingTimeDesc *prometheus.Desc
@@ -22,9 +22,11 @@ type peerCollector struct {
2222
lnd lnrpc.LightningClient
2323
}
2424

25-
func newPeerCollector(lnd lnrpc.LightningClient) *peerCollector {
25+
// NewPeerCollector returns a new instance of the PeerCollector for the target
26+
// lnd client.
27+
func NewPeerCollector(lnd lnrpc.LightningClient) *PeerCollector {
2628
perPeerLabels := []string{"pubkey"}
27-
return &peerCollector{
29+
return &PeerCollector{
2830
peerCountDesc: prometheus.NewDesc(
2931
"lnd_peer_count", "total number of peers",
3032
nil, nil,
@@ -60,7 +62,7 @@ func newPeerCollector(lnd lnrpc.LightningClient) *peerCollector {
6062
// last descriptor has been sent.
6163
//
6264
// NOTE: Part of the prometheus.Collector interface.
63-
func (p *peerCollector) Describe(ch chan<- *prometheus.Desc) {
65+
func (p *PeerCollector) Describe(ch chan<- *prometheus.Desc) {
6466
ch <- p.peerCountDesc
6567

6668
ch <- p.pingTimeDesc
@@ -75,7 +77,7 @@ func (p *peerCollector) Describe(ch chan<- *prometheus.Desc) {
7577
// Collect is called by the Prometheus registry when collecting metrics.
7678
//
7779
// NOTE: Part of the prometheus.Collector interface.
78-
func (p *peerCollector) Collect(ch chan<- prometheus.Metric) {
80+
func (p *PeerCollector) Collect(ch chan<- prometheus.Metric) {
7981
listPeersResp, err := p.lnd.ListPeers(
8082
context.Background(), &lnrpc.ListPeersRequest{},
8183
)
@@ -116,7 +118,7 @@ func (p *peerCollector) Collect(ch chan<- prometheus.Metric) {
116118
func init() {
117119
metricsMtx.Lock()
118120
collectors["peer"] = func(lnd lnrpc.LightningClient) prometheus.Collector {
119-
collector := newPeerCollector(lnd)
121+
collector := NewPeerCollector(lnd)
120122
return prometheus.Collector(collector)
121123
}
122124
metricsMtx.Unlock()

collectors/wallet_collector.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/prometheus/client_golang/prometheus"
99
)
1010

11-
// walletCollector is a collector that will export metrics related to lnd's
11+
// WalletCollector is a collector that will export metrics related to lnd's
1212
// on-chain wallet. .
13-
type walletCollector struct {
13+
type WalletCollector struct {
1414
lnd lnrpc.LightningClient
1515

1616
// We'll use two gauges to keep track of the total number of confirmed
@@ -32,10 +32,10 @@ type walletCollector struct {
3232
txNumConfsDesc *prometheus.Desc
3333
}
3434

35-
// newWalletCollector returns a new instance of the walletCollector.
36-
func newWalletCollector(lnd lnrpc.LightningClient) *walletCollector {
35+
// NewWalletCollector returns a new instance of the WalletCollector.
36+
func NewWalletCollector(lnd lnrpc.LightningClient) *WalletCollector {
3737
txLabels := []string{"tx_hash"}
38-
return &walletCollector{
38+
return &WalletCollector{
3939
lnd: lnd,
4040
numUtxosConfDesc: prometheus.NewDesc(
4141
"lnd_utxos_count_confirmed_total",
@@ -78,7 +78,7 @@ func newWalletCollector(lnd lnrpc.LightningClient) *walletCollector {
7878
// last descriptor has been sent.
7979
//
8080
// NOTE: Part of the prometheus.Collector interface.
81-
func (u *walletCollector) Describe(ch chan<- *prometheus.Desc) {
81+
func (u *WalletCollector) Describe(ch chan<- *prometheus.Desc) {
8282
ch <- u.numUtxosConfDesc
8383
ch <- u.numUtxosUnconfDesc
8484
ch <- u.minUtxoSizeDesc
@@ -92,7 +92,7 @@ func (u *walletCollector) Describe(ch chan<- *prometheus.Desc) {
9292
// Collect is called by the Prometheus registry when collecting metrics.
9393
//
9494
// NOTE: Part of the prometheus.Collector interface.
95-
func (u *walletCollector) Collect(ch chan<- prometheus.Metric) {
95+
func (u *WalletCollector) Collect(ch chan<- prometheus.Metric) {
9696
// First, we'll fetch information w.r.t all UTXOs in the wallet. The
9797
// large max confs value means we'll capture all the UTXOs.
9898
req := &lnrpc.ListUnspentRequest{
@@ -192,7 +192,7 @@ func (u *walletCollector) Collect(ch chan<- prometheus.Metric) {
192192
func init() {
193193
metricsMtx.Lock()
194194
collectors["wallet"] = func(lnd lnrpc.LightningClient) prometheus.Collector {
195-
return newWalletCollector(lnd)
195+
return NewWalletCollector(lnd)
196196
}
197197
metricsMtx.Unlock()
198198
}

0 commit comments

Comments
 (0)