1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/contrib/munin/lokinet-munin.py

74 lines
2.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
#
# requires python3-requests
#
import requests
import json
2019-05-27 13:22:48 +02:00
import os
import sys
2019-05-27 13:08:59 +02:00
from collections import defaultdict as Dict
from requests.exceptions import RequestException
def jsonrpc(method, **args):
return requests.post('http://127.0.0.1:1190/', data=json.dumps(
2019-05-27 13:08:59 +02:00
{'method': method, 'params': args, 'id': 'munin'}), headers={'content-type': 'application/json'}).json()
2019-05-27 13:29:13 +02:00
def exit_sessions_main(exe):
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 13:29:13 +02:00
print("{}.sessions.info Number of exit sessions".format(exe))
print("{}.sessions.label sessions".format(exe))
else:
count = 0
try:
j = jsonrpc("llarp.admin.exit.list")
count = len(j['result'])
except RequestException:
pass
2019-05-27 13:52:04 +02:00
print("{}.sessions.value {}".format(exe, count))
2019-05-27 13:29:13 +02:00
def peers_main(exe):
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print("graph_title lokinet peers")
2018-11-20 15:40:31 +01: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 13:29:13 +02:00
print("{}.outbound.info Number of outbound lokinet peers".format(exe))
print("{}.inbound.info Number of inbound lokinet peers".format(exe))
print("{}.outbound.label outbound peers".format(exe))
print("{}.inbound.label inbound peers".format(exe))
else:
2019-05-27 13:08:59 +02:00
inbound = Dict(int)
outbound = Dict(int)
try:
j = jsonrpc("llarp.admin.link.neighboors")
for peer in j['result']:
if peer["outbound"]:
2019-05-27 13:08:59 +02:00
outbound[peer['ident']] += 1
else:
2019-05-27 13:08:59 +02:00
inbound[peer['ident']] += 1
except RequestException:
pass
2019-05-27 13:52:04 +02:00
print("{}.outbound.value {}".format(exe, len(outbound)))
print("{}.inbound.value {}".format(exe, len(inbound)))
if __name__ == '__main__':
2019-05-27 13:22:48 +02:00
exe = os.path.basename(sys.argv[0]).lower()
2019-05-27 13:34:28 +02:00
if exe == 'lokinet_peers':
2019-05-27 13:29:13 +02:00
peers_main(exe)
2019-05-27 13:34:28 +02:00
elif exe == 'lokinet_exit':
2019-05-27 13:29:13 +02:00
exit_sessions_main(exe)
else:
print(
2019-05-27 13:34:28 +02:00
'please symlink this as `lokinet_peers` or `lokinet_exit` in munin plugins dir')