Skip to content

Commit a6a4022

Browse files
s373nZcdecker
authored andcommitted
prometheus: Add PeersCollector to track raw peers from listpeers.
Tracks direct peer information about peers which don't necessarily have a channel. Generally reinstates changes from: ce078bb#diff-cfc589c146eeee8db6b2db1d8dc6e851722e6ea18a2d7d05ebc49b2851012de1R71-L91
1 parent 16f6824 commit a6a4022

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

prometheus/prometheus.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ def collect(self):
8080
value=channel_funds,
8181
)
8282

83+
class PeersCollector(BaseLnCollector):
84+
def collect(self):
85+
peers = self.rpc.listpeers()['peers']
86+
87+
connected = GaugeMetricFamily(
88+
'lightning_peer_connected',
89+
'Is the peer currently connected?',
90+
labels=['id'],
91+
)
92+
count = GaugeMetricFamily(
93+
'lightning_peers',
94+
"The number of peers",
95+
labels=['id'],
96+
)
97+
98+
for p in peers:
99+
labels = [p['id']]
100+
count.add_metric(labels, 1)
101+
connected.add_metric(labels, int(p['connected']))
102+
103+
return [count, connected]
104+
83105

84106
class PeerChannelsCollector(BaseLnCollector):
85107
def collect(self):
@@ -233,6 +255,7 @@ def init(options, configuration, plugin):
233255
registry.register(NodeCollector(plugin.rpc, registry))
234256
registry.register(FundsCollector(plugin.rpc, registry))
235257
registry.register(PeerChannelsCollector(plugin.rpc, registry))
258+
registry.register(PeersCollector(plugin.rpc, registry))
236259
registry.register(ChannelsCollector(plugin.rpc, registry))
237260

238261

0 commit comments

Comments
 (0)