prom: More msat-purge...

This commit is contained in:
Christian Decker
2023-07-19 19:09:54 +02:00
parent a3d3388d6a
commit ce078bb74e
2 changed files with 48 additions and 28 deletions

View File

@@ -32,7 +32,6 @@ class NodeCollector(BaseLnCollector):
value=blockheight, value=blockheight,
) )
print(info)
fees_msat = int(info.get( fees_msat = int(info.get(
"fees_collected_msat", "fees_collected_msat",
info.get("msatoshi_fees_collected", None) info.get("msatoshi_fees_collected", None)
@@ -88,10 +87,19 @@ class PeerCollector(BaseLnCollector):
labels=['id'], labels=['id'],
) )
for p in peers: channels = self.rpc.listpeerchannels()['channels']
labels = [p['id']] # Associate each channel with a peer
count.add_metric(labels, len(p['channels'])) peers = {}
connected.add_metric(labels, int(p['connected'])) conn = {}
for c in channels:
peer_id = c['peer_id']
peers[peer_id] = peers.get(peer_id, 0) + 1
conn[peer_id] = conn.get(peer_id, 0) + c['peer_connected']
for p in peers.keys():
labels = [p]
count.add_metric(labels, peers[p])
connected.add_metric(labels, conn.get(p, 0))
return [count, connected] return [count, connected]
@@ -163,32 +171,31 @@ class ChannelsCollector(BaseLnCollector):
labels=['id', 'scid', 'alias'], labels=['id', 'scid', 'alias'],
) )
peers = self.rpc.listpeers()['peers'] channels = self.rpc.listpeerchannels()['channels']
for p in peers: for c in channels:
for c in p['channels']: # append alias for human readable labels, if no label is found fill with shortid.
# append alias for human readable labels, if no label is found fill with shortid. node = self.rpc.listnodes(c['peer_id'])['nodes']
node = self.rpc.listnodes(p['id'])['nodes'] if len(node) != 0 and 'alias' in node[0]:
if len(node) != 0 and 'alias' in node[0]: alias = node[0]['alias']
alias = node[0]['alias'] else:
else: alias = 'unknown'
alias = 'unknown'
labels = [p['id'], c.get('short_channel_id', c.get('channel_id')), alias] labels = [c['peer_id'], c.get('short_channel_id', c.get('channel_id')), alias]
balance_gauge.add_metric(labels, c['to_us_msat'].to_satoshi()) balance_gauge.add_metric(labels, c['to_us_msat'].to_satoshi())
spendable_gauge.add_metric(labels, spendable_gauge.add_metric(labels,
c['spendable_msat'].to_satoshi()) c['spendable_msat'].to_satoshi())
total_gauge.add_metric(labels, c['total_msat'].to_satoshi()) total_gauge.add_metric(labels, c['total_msat'].to_satoshi())
htlc_gauge.add_metric(labels, len(c['htlcs'])) htlc_gauge.add_metric(labels, len(c['htlcs']))
in_payments_offered_gauge.add_metric(labels, c['in_payments_offered']) in_payments_offered_gauge.add_metric(labels, c['in_payments_offered'])
in_payments_fulfilled_gauge.add_metric(labels, c['in_payments_fulfilled']) in_payments_fulfilled_gauge.add_metric(labels, c['in_payments_fulfilled'])
in_msatoshi_offered_gauge.add_metric(labels, c['in_msatoshi_offered']) in_msatoshi_offered_gauge.add_metric(labels, int(c['in_offered_msat']))
in_msatoshi_fulfilled_gauge.add_metric(labels, c['in_msatoshi_fulfilled']) in_msatoshi_fulfilled_gauge.add_metric(labels, int(c['in_fulfilled_msat']))
out_payments_offered_gauge.add_metric(labels, c['out_payments_offered']) out_payments_offered_gauge.add_metric(labels, c['out_payments_offered'])
out_payments_fulfilled_gauge.add_metric(labels, c['out_payments_fulfilled']) out_payments_fulfilled_gauge.add_metric(labels, c['out_payments_fulfilled'])
out_msatoshi_offered_gauge.add_metric(labels, c['out_msatoshi_offered']) out_msatoshi_offered_gauge.add_metric(labels, int(c['out_offered_msat']))
out_msatoshi_fulfilled_gauge.add_metric(labels, c['out_msatoshi_fulfilled']) out_msatoshi_fulfilled_gauge.add_metric(labels, int(c['out_fulfilled_msat']))
return [ return [
htlc_gauge, htlc_gauge,

View File

@@ -1,6 +1,7 @@
import os import os
from pyln.testing.fixtures import * # noqa: F401,F403 from pyln.testing.fixtures import * # noqa: F401,F403
import urllib import urllib
from ephemeral_port_reserve import reserve
plugin_path = os.path.join(os.path.dirname(__file__), "prometheus.py") plugin_path = os.path.join(os.path.dirname(__file__), "prometheus.py")
@@ -25,3 +26,15 @@ def test_prometheus_scrape(node_factory):
def test_prometheus_channels(node_factory):
port = reserve()
l1, l2, l3 = node_factory.line_graph(
3,
opts=[
{},
{'plugin': plugin_path, 'prometheus-listen': f'127.0.0.1:{port}'},
{}
]
)
scrape = urllib.request.urlopen(f'http://localhost:{port}')
print(scrape)