mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-19 14:14:20 +01:00
added a monitoring plugin to see health of peers and channels
This commit is contained in:
@@ -12,6 +12,7 @@ Community curated plugins for c-lightning.
|
||||
| [donations][donations] | A simple donations page to accept donations from the web |
|
||||
| [graphql][graphql] | Exposes the c-lightning API over [graphql][graphql-spec] |
|
||||
| [lightning-qt][lightning-qt] | A bitcoin-qt-like GUI for lightningd |
|
||||
| [monitor][monitor] | helps you analyze the health of your peers and channels |
|
||||
| [persistent-channels][pers-chans] | Maintains a number of channels to peers |
|
||||
| [probe][probe] | Regularly probes the network for stability |
|
||||
| [prometheus][prometheus] | Lightning node exporter for the prometheus timeseries server |
|
||||
@@ -105,3 +106,4 @@ your environment.
|
||||
[lightning-qt]: https://github.com/darosior/pylightning-qt
|
||||
[cpp-api]: https://github.com/darosior/lightningcpp
|
||||
[js-api]: https://github.com/darosior/clightningjs
|
||||
[monitor]: https://github.com/renepickhardt/plugins/tree/master/monitor
|
||||
|
||||
44
monitor/README.md
Normal file
44
monitor/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Monitor plugin
|
||||
|
||||
Monitors the health of your peers and helps you to decide if you might want to close a channel
|
||||
|
||||
## Installation
|
||||
|
||||
For general plugin installation instructions see the repos main
|
||||
[README.md](https://github.com/lightningd/plugins/blob/master/README.md#Installation)
|
||||
|
||||
## Example Usage
|
||||
|
||||
Unfortunately the python plugin framework doesn't pretty-print, nor does
|
||||
lightning-cli, so best viewed with -H (sorry for all the slasshes in the output. nothing I can do about it at this point):
|
||||
|
||||
```
|
||||
lightning-cli -H monitor
|
||||
|
||||
{
|
||||
\"num_connected\": 26,
|
||||
\"num_channels\": 37,
|
||||
\"states\": [
|
||||
\"CHANNELD_NORMAL: 37\"
|
||||
],
|
||||
\"channels\": {
|
||||
\"CHANNELD_NORMAL\": [
|
||||
\"024a8228d764091fce2ed67e1a7404f83e38ea3c7cb42030a2789e73cf3b341365\ connected\ their fees\ xx.xx% owned by us\ 537914x2372x0\",
|
||||
\"032e04b67641c00444af1d83145c0b63bac8316a6afb8fec0f87938295ed8bb129\ disconnected\ their fees\ xx.xx% owned by us\ 539125x1288x0\",
|
||||
\"0279c22ed7a068d10dc1a38ae66d2d6461e269226c60258c021b1ddcdfe4b00bc4\ connected\ our fees\ xx.xx% owned by us\ 539467x852x0\",
|
||||
...
|
||||
\"0227d5b940cba21be92244953475ccdd3cefbed8f397be03e3155a5f41f304fc93\ connected\ their fees\ xx.xx% owned by us\ 581418x2157x0\"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
As you can see you will see a list of channels to which you are connected or disconnected. How much percent of the funds is owned by you and who has to pay the fees in case of force channel closing.
|
||||
|
||||
|
||||
Or if you just want to see the channels which are currently disconnected from peers
|
||||
|
||||
```
|
||||
lightning-cli -H monitor | grep "disconnected"
|
||||
```
|
||||
|
||||
78
monitor/monitor.py
Executable file
78
monitor/monitor.py
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
|
||||
This is a quick hack and adopted plugin from the summary.py plugin (orinigally written by Rusty Russell
|
||||
|
||||
This one is adapted by Rene Pickhardt and aimed to help you identify inactive channels quickly
|
||||
|
||||
"""
|
||||
|
||||
from lightning import Plugin, Millisatoshi
|
||||
import lightning
|
||||
import json
|
||||
|
||||
plugin = Plugin(autopatch=True)
|
||||
|
||||
# __version__ was introduced in 0.0.7.1, with utf8 passthrough support.
|
||||
try:
|
||||
if version.parse(lightning.__version__) >= version.parse("0.0.7.1"):
|
||||
have_utf8 = True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@plugin.method("monitor")
|
||||
def monitor(plugin):
|
||||
"""Monitors channels of this node."""
|
||||
|
||||
reply = {}
|
||||
reply['num_connected'] = 0
|
||||
reply['num_channels'] = 0
|
||||
peers = plugin.rpc.listpeers()
|
||||
info = plugin.rpc.getinfo()
|
||||
nid = info["id"]
|
||||
chans={}
|
||||
states={}
|
||||
for p in peers['peers']:
|
||||
for c in p['channels']:
|
||||
if p['connected']:
|
||||
reply['num_connected'] += 1
|
||||
reply['num_channels'] += 1
|
||||
state = c['state']
|
||||
if state in states:
|
||||
states[state]+=1
|
||||
else:
|
||||
states[state]=1
|
||||
connected = "connected"
|
||||
if p['connected'] != True:
|
||||
connected = "disconnected"
|
||||
funding = c['funding_allocation_msat']
|
||||
our_funding = funding[nid]
|
||||
fees = "our fees"
|
||||
if int(our_funding) == 0:
|
||||
fees = "their fees"
|
||||
|
||||
|
||||
total = float(c['msatoshi_total'])
|
||||
ours = float(c['our_channel_reserve_satoshis']) + float(c['spendable_msatoshi'])
|
||||
our_fraction = "{:4.2f}% owned by us".format(ours*100/total)
|
||||
tmp = "\t".join([p['id'], connected, fees, our_fraction, c['short_channel_id']])
|
||||
|
||||
if state in chans:
|
||||
chans[state].append(tmp)
|
||||
else:
|
||||
chans[state] = [tmp]
|
||||
|
||||
serialized_states = []
|
||||
for key, value in states.items():
|
||||
serialized_states.append(key + ": " + str(value))
|
||||
reply['states']=serialized_states
|
||||
reply['channels'] = chans#json.dumps(chans)
|
||||
reply = json.dumps(reply, indent=4)
|
||||
return reply
|
||||
|
||||
|
||||
@plugin.init()
|
||||
def init(options, configuration, plugin):
|
||||
plugin.log("Plugin monitor.py initialized")
|
||||
|
||||
plugin.run()
|
||||
2
monitor/requirements.txt
Normal file
2
monitor/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
pylightning>=0.0.6
|
||||
|
||||
Reference in New Issue
Block a user