2018-10-26 13:02:15 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# requires python3-requests
|
|
|
|
#
|
|
|
|
import requests
|
|
|
|
import json
|
2019-05-27 11:22:48 +00:00
|
|
|
import os
|
2018-10-26 13:02:15 +00:00
|
|
|
import sys
|
|
|
|
|
2019-05-27 11:08:59 +00:00
|
|
|
from collections import defaultdict as Dict
|
|
|
|
|
2019-05-21 08:58:43 +00:00
|
|
|
from requests.exceptions import RequestException
|
|
|
|
|
2018-10-26 13:02:15 +00:00
|
|
|
|
|
|
|
def jsonrpc(method, **args):
|
|
|
|
return requests.post('http://127.0.0.1:1190/', data=json.dumps(
|
2019-05-27 11:08:59 +00:00
|
|
|
{'method': method, 'params': args, 'id': 'munin'}), headers={'content-type': 'application/json'}).json()
|
2018-10-26 13:02:15 +00:00
|
|
|
|
|
|
|
|
2019-05-27 12:00:02 +00:00
|
|
|
def exit_sessions_main():
|
2018-12-10 17:22:59 +00:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
|
|
|
print("graph_title lokinet exit sessions")
|
|
|
|
print("graph_vlabel sessions")
|
|
|
|
print("graph_category network")
|
|
|
|
print("graph_info This graph shows the number of exit sessions on a lokinet exit")
|
2019-05-27 12:00:02 +00:00
|
|
|
print("_exit_sessions.info Number of exit sessions")
|
|
|
|
print("_exit_sessions.label sessions")
|
2018-12-10 17:22:59 +00:00
|
|
|
else:
|
|
|
|
count = 0
|
|
|
|
try:
|
|
|
|
j = jsonrpc("llarp.admin.exit.list")
|
|
|
|
count = len(j['result'])
|
2019-05-21 08:58:43 +00:00
|
|
|
except RequestException:
|
2018-12-10 17:22:59 +00:00
|
|
|
pass
|
2019-05-27 12:00:02 +00:00
|
|
|
print("_exit_sessions.value {}".format(count))
|
2018-12-10 17:22:59 +00:00
|
|
|
|
|
|
|
|
2019-05-27 12:00:02 +00:00
|
|
|
def peers_main():
|
2018-10-26 13:02:15 +00:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
|
|
|
print("graph_title lokinet peers")
|
2018-11-20 14:40:31 +00:00
|
|
|
print("graph_vlabel peers")
|
|
|
|
print("graph_category network")
|
|
|
|
print("graph_info This graph shows the number of node to node sessions of this lokinet router")
|
2019-05-27 12:00:02 +00:00
|
|
|
print("_peers_outbound.info Number of outbound lokinet peers")
|
|
|
|
print("_peers_inbound.info Number of inbound lokinet peers")
|
|
|
|
print("_peers_outbound.label outbound peers")
|
|
|
|
print("_peers_inbound.label inbound peers")
|
2019-05-27 12:22:51 +00:00
|
|
|
print("_peers_clients.info Number of lokinet client peers")
|
|
|
|
print("_peers_clients.label lokinet client peers")
|
2018-10-26 13:02:15 +00:00
|
|
|
else:
|
2019-05-27 11:08:59 +00:00
|
|
|
inbound = Dict(int)
|
|
|
|
outbound = Dict(int)
|
2019-05-27 12:22:51 +00:00
|
|
|
clients = Dict(int)
|
2018-10-26 13:02:15 +00:00
|
|
|
try:
|
|
|
|
j = jsonrpc("llarp.admin.link.neighboors")
|
|
|
|
for peer in j['result']:
|
2019-05-27 12:22:51 +00:00
|
|
|
if peer["svcnode"]:
|
|
|
|
if peer["outbound"]:
|
|
|
|
outbound[peer['ident']] += 1
|
|
|
|
else:
|
|
|
|
inbound[peer['ident']] += 1
|
2018-10-26 13:02:15 +00:00
|
|
|
else:
|
2019-05-27 12:22:51 +00:00
|
|
|
clients[peer['ident']] += 1
|
2019-05-21 08:58:43 +00:00
|
|
|
except RequestException:
|
2018-10-26 13:02:15 +00:00
|
|
|
pass
|
|
|
|
|
2019-05-27 12:00:02 +00:00
|
|
|
print("_peers_outbound.value {}".format(len(outbound)))
|
|
|
|
print("_peers_inbound.value {}".format(len(inbound)))
|
2019-05-27 12:22:51 +00:00
|
|
|
print("_peers_clients.value {}".format(len(clients)))
|
2018-10-26 13:02:15 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-05-27 11:22:48 +00:00
|
|
|
exe = os.path.basename(sys.argv[0]).lower()
|
2019-05-27 11:34:28 +00:00
|
|
|
if exe == 'lokinet_peers':
|
2019-05-27 12:00:02 +00:00
|
|
|
peers_main()
|
2019-05-27 11:34:28 +00:00
|
|
|
elif exe == 'lokinet_exit':
|
2019-05-27 12:00:02 +00:00
|
|
|
exit_sessions_main()
|
2018-12-10 17:22:59 +00:00
|
|
|
else:
|
2019-01-03 23:10:32 +00:00
|
|
|
print(
|
2019-05-27 11:34:28 +00:00
|
|
|
'please symlink this as `lokinet_peers` or `lokinet_exit` in munin plugins dir')
|