2019-08-12 11:36:23 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-05-23 19:36:25 +00:00
|
|
|
|
|
|
|
import curses
|
2019-08-12 11:36:23 +00:00
|
|
|
import json
|
2020-05-23 19:36:25 +00:00
|
|
|
import sys
|
2019-08-12 11:36:23 +00:00
|
|
|
import time
|
2020-05-23 19:36:25 +00:00
|
|
|
|
|
|
|
import zmq
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2021-05-01 12:44:37 +00:00
|
|
|
geo = None
|
|
|
|
|
|
|
|
try:
|
|
|
|
import GeoIP
|
|
|
|
geo = GeoIP.open("/usr/share/GeoIP/GeoIP.dat", GeoIP.GEOIP_STANDARD)
|
|
|
|
except Exception as ex:
|
|
|
|
print('no geoip: {}'.format(ex))
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
def ip_to_flag(ip):
|
|
|
|
"""
|
|
|
|
convert an ip to a flag emoji
|
|
|
|
"""
|
|
|
|
# bail if no geoip available
|
|
|
|
if not geo:
|
|
|
|
return ''
|
|
|
|
# trim off excess ipv6 jizz
|
|
|
|
ip = ip.replace("::ffff:", "")
|
|
|
|
# get the country code
|
|
|
|
cc = geo.country_code_by_addr(ip)
|
|
|
|
# Unicode flag sequences are just country codes transposed into the REGIONAL
|
|
|
|
# INDICATOR SYMBOL LETTER A ... Z range (U+1F1E6 ... U+1F1FF):
|
|
|
|
flag = ''.join(chr(0x1f1e6 + ord(i) - ord('A')) for i in cc)
|
|
|
|
return '({}) {}'.format(cc, flag)
|
|
|
|
|
2019-08-12 11:36:23 +00:00
|
|
|
|
|
|
|
class Monitor:
|
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
_sample_size = 12
|
2019-08-12 11:36:23 +00:00
|
|
|
|
|
|
|
def __init__(self, url):
|
2020-05-23 19:36:25 +00:00
|
|
|
self.txrate = 0
|
|
|
|
self.rxrate = 0
|
2019-08-12 11:36:23 +00:00
|
|
|
self.data = dict()
|
|
|
|
self.win = curses.initscr()
|
2020-05-21 14:18:23 +00:00
|
|
|
curses.start_color()
|
|
|
|
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
|
2020-05-23 19:36:25 +00:00
|
|
|
self._rpc_context = zmq.Context()
|
|
|
|
self._rpc_socket = self._rpc_context.socket(zmq.DEALER)
|
|
|
|
self._rpc_socket.setsockopt(zmq.CONNECT_TIMEOUT, 5000)
|
|
|
|
self._rpc_socket.setsockopt(zmq.HANDSHAKE_IVL, 5000)
|
|
|
|
self._rpc_socket.connect(url)
|
|
|
|
self._speed_samples = [(0,0,0,0)] * self._sample_size
|
|
|
|
self._run = True
|
2021-05-01 12:44:37 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def rpc(self, method):
|
|
|
|
self._rpc_socket.send_multipart([method.encode(), b'lokinetmon'+method.encode()])
|
|
|
|
if not self._rpc_socket.poll(timeout=50):
|
|
|
|
return
|
|
|
|
reply = self._rpc_socket.recv_multipart()
|
|
|
|
if len(reply) >= 3 and reply[0:2] == [b'REPLY', b'lokinetmon'+method.encode()]:
|
|
|
|
return reply[2].decode()
|
2021-05-01 12:44:37 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def _close(self):
|
|
|
|
self._rpc_socket.close(linger=0)
|
2021-05-01 12:44:37 +00:00
|
|
|
self._run = False
|
2019-08-12 11:36:23 +00:00
|
|
|
curses.endwin()
|
|
|
|
|
|
|
|
def update_data(self):
|
|
|
|
"""update data from lokinet"""
|
|
|
|
try:
|
2020-10-27 19:03:06 +00:00
|
|
|
data = json.loads(self.rpc("llarp.status"))
|
|
|
|
self.data = data['result']
|
2020-05-23 19:36:25 +00:00
|
|
|
except:
|
2019-08-12 11:36:23 +00:00
|
|
|
self.data = None
|
2020-05-23 19:36:25 +00:00
|
|
|
return self.data is not None and self._run
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def _render_path(self, y_pos, path, name):
|
2019-08-12 11:36:23 +00:00
|
|
|
"""render a path at current position"""
|
2020-05-23 19:36:25 +00:00
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("({}) ".format(name))
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
y_pos += 1
|
|
|
|
self.win.addstr("[tx:\t{}]\t[rx:\t{}]".format(
|
|
|
|
self.speed_of(path['txRateCurrent']), self.speed_of(path['rxRateCurrent'])))
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
y_pos += 1
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("me -> ")
|
|
|
|
for hop in path["hops"]:
|
2021-05-01 12:44:37 +00:00
|
|
|
hopstr = hop['router'][:4]
|
|
|
|
if 'ip' in hop:
|
|
|
|
hopstr += ' {}'.format(ip_to_flag(hop['ip']))
|
|
|
|
self.win.addstr(" {} ->".format(hopstr))
|
|
|
|
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr(" [{} ms latency]".format(path["intro"]["latency"]))
|
2020-05-23 19:36:25 +00:00
|
|
|
self.win.addstr(" [{} until expire]".format(self.time_to(path["expiresAt"])))
|
2019-08-12 11:36:23 +00:00
|
|
|
if path["expiresSoon"]:
|
|
|
|
self.win.addstr("(expiring)")
|
|
|
|
elif path["expired"]:
|
|
|
|
self.win.addstr("(expired)")
|
2020-05-23 19:36:25 +00:00
|
|
|
return y_pos
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
@staticmethod
|
|
|
|
def time_to(timestamp):
|
2019-08-12 11:36:23 +00:00
|
|
|
""" return time until timestamp in seconds formatted"""
|
|
|
|
now = time.time() * 1000
|
2020-05-23 19:36:25 +00:00
|
|
|
return "{} seconds".format(int((timestamp - now) / 1000))
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
@staticmethod
|
|
|
|
def speed_of(rate):
|
2019-08-12 11:36:23 +00:00
|
|
|
"""turn int speed into string formatted"""
|
2020-05-23 19:36:25 +00:00
|
|
|
units = ["b", "Kb", "Mb", "Gb"]
|
2019-08-12 11:36:23 +00:00
|
|
|
idx = 0
|
2020-05-23 19:36:25 +00:00
|
|
|
rate *= 8
|
2019-08-12 11:36:23 +00:00
|
|
|
while rate > 1000 and idx < len(units):
|
|
|
|
rate /= 1000.0
|
|
|
|
idx += 1
|
|
|
|
return "{} {}ps".format("%.2f" % rate, units[idx])
|
|
|
|
|
2020-05-21 14:18:23 +00:00
|
|
|
def get_all_paths(self):
|
2020-05-23 19:36:25 +00:00
|
|
|
""" yield all paths in current data """
|
|
|
|
for key in self.data['services']:
|
|
|
|
status = self.data['services'][key]
|
2020-05-21 14:18:23 +00:00
|
|
|
for path in (status['paths'] or []):
|
|
|
|
yield path
|
2020-05-23 19:36:25 +00:00
|
|
|
for sess in (status['remoteSessions'] or []):
|
|
|
|
for path in sess['paths']:
|
2020-05-21 14:18:23 +00:00
|
|
|
yield path
|
2020-05-23 19:36:25 +00:00
|
|
|
for sess in (status['snodeSessions'] or []):
|
|
|
|
for path in sess['paths']:
|
2020-05-21 14:18:23 +00:00
|
|
|
yield path
|
2020-05-23 19:36:25 +00:00
|
|
|
|
|
|
|
def display_service(self, y_pos, name, status):
|
2019-08-12 11:36:23 +00:00
|
|
|
"""display a service at current position"""
|
2020-05-23 19:36:25 +00:00
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("service [{}]".format(name))
|
|
|
|
build = status["buildStats"]
|
|
|
|
ratio = build["success"] / (build["attempts"] or 1)
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("build success: {} %".format(int(100 * ratio)))
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
paths = status["paths"]
|
|
|
|
self.win.addstr("paths: {}".format(len(paths)))
|
|
|
|
for path in paths:
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = self._render_path(y_pos, path, "inbound")
|
2020-02-07 17:25:42 +00:00
|
|
|
for session in (status["remoteSessions"] or []):
|
2019-08-12 11:36:23 +00:00
|
|
|
for path in session["paths"]:
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = self._render_path(
|
|
|
|
y_pos, path, "[active] {}".format(session["currentConvoTag"])
|
2019-08-12 11:36:23 +00:00
|
|
|
)
|
2020-02-07 17:25:42 +00:00
|
|
|
for session in (status["snodeSessions"] or []):
|
2019-08-12 11:36:23 +00:00
|
|
|
for path in session["paths"]:
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = self._render_path(y_pos, path, "[snode]")
|
|
|
|
return y_pos
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def display_links(self, y_pos, data):
|
|
|
|
""" display links section """
|
2019-08-12 11:36:23 +00:00
|
|
|
self.txrate = 0
|
|
|
|
self.rxrate = 0
|
|
|
|
for link in data["outbound"]:
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("outbound sessions:")
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = self.display_link(y_pos, link)
|
2019-08-12 11:36:23 +00:00
|
|
|
for link in data["inbound"]:
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("inbound sessions:")
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = self.display_link(y_pos, link)
|
|
|
|
y_pos += 2
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr(
|
2020-05-21 14:18:23 +00:00
|
|
|
"throughput:\t\t[{}\ttx]\t[{}\trx]".format(
|
2020-05-23 19:36:25 +00:00
|
|
|
self.speed_of(self.txrate), self.speed_of(self.rxrate)
|
2019-08-12 11:36:23 +00:00
|
|
|
)
|
|
|
|
)
|
2020-05-23 19:36:25 +00:00
|
|
|
bloat_tx, bloat_rx = self.calculate_bloat(self.data['links']['outbound'])
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
self.win.addstr("goodput:\t\t[{}\ttx]\t[{}\trx]".format(
|
|
|
|
self.speed_of(self.txrate-bloat_tx), self.speed_of(self.rxrate-bloat_rx)))
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
self.win.addstr("overhead:\t\t[{}\ttx]\t[{}\trx]".format(
|
|
|
|
self.speed_of(bloat_tx), self.speed_of(bloat_rx)))
|
|
|
|
self._speed_samples.append((self.txrate, self.rxrate, bloat_tx, bloat_rx))
|
|
|
|
while len(self._speed_samples) > self._sample_size:
|
|
|
|
self._speed_samples.pop(0)
|
|
|
|
return self.display_speedgraph(y_pos + 2)
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
@staticmethod
|
|
|
|
def _scale(_x, _n):
|
|
|
|
while _n > 0:
|
|
|
|
_x /= 2
|
|
|
|
_n -= 1
|
|
|
|
return int(_x)
|
2019-08-12 11:36:23 +00:00
|
|
|
|
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
@staticmethod
|
|
|
|
def _makebar(samp, badsamp, maxsamp):
|
|
|
|
barstr = "#" * (samp - badsamp)
|
|
|
|
pad = " " * (maxsamp - samp)
|
|
|
|
return pad, barstr, '#' * badsamp
|
2021-05-01 12:44:37 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def display_speedgraph(self, y_pos, maxsz=40):
|
|
|
|
""" display global speed graph """
|
2020-05-21 14:18:23 +00:00
|
|
|
txmax, rxmax = 1024, 1024
|
2020-05-23 19:36:25 +00:00
|
|
|
for _tx, _rx, b_tx, b_rx in self._speed_samples:
|
|
|
|
if _tx > txmax:
|
|
|
|
txmax = _tx
|
|
|
|
if _rx > rxmax:
|
|
|
|
rxmax = _rx
|
2019-08-12 11:36:23 +00:00
|
|
|
|
|
|
|
rxscale = 0
|
|
|
|
while rxmax > maxsz:
|
|
|
|
rxscale += 1
|
|
|
|
rxmax /= 2
|
|
|
|
|
|
|
|
txscale = 0
|
|
|
|
while txmax > maxsz:
|
|
|
|
txscale += 1
|
|
|
|
txmax /= 2
|
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
txlabelpad = int(txmax / 2)
|
|
|
|
rxlabelpad = int(rxmax / 2)
|
2019-08-12 11:36:23 +00:00
|
|
|
if txlabelpad <= 0:
|
|
|
|
txlabelpad = 1
|
|
|
|
if rxlabelpad <= 0:
|
|
|
|
rxlabelpad = 1
|
2020-05-23 19:36:25 +00:00
|
|
|
txlabelpad_str = " " * txlabelpad
|
|
|
|
rxlabelpad_str = " " * rxlabelpad
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
for val in [txlabelpad_str, 'tx', txlabelpad_str, rxlabelpad_str, 'rx', rxlabelpad_str]:
|
|
|
|
self.win.addstr(val)
|
|
|
|
for _tx, _rx, b_tx, b_rx in self._speed_samples:
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
txpad, txbar, btxbar = self._makebar(self._scale(_tx, txscale), self._scale(b_tx, txscale), int(txmax))
|
|
|
|
rxpad, rxbar, brxbar = self._makebar(self._scale(_rx, rxscale), self._scale(b_rx, rxscale), int(rxmax))
|
2020-05-21 14:18:23 +00:00
|
|
|
self.win.addstr(txpad)
|
|
|
|
self.win.addstr(btxbar, curses.color_pair(1))
|
|
|
|
self.win.addstr(txbar)
|
|
|
|
self.win.addstr('|')
|
|
|
|
self.win.addstr(rxbar)
|
|
|
|
self.win.addstr(brxbar, curses.color_pair(1))
|
|
|
|
self.win.addstr(rxpad)
|
2020-05-23 19:36:25 +00:00
|
|
|
return y_pos + 2
|
2020-05-21 14:18:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def calculate_bloat(self, links):
|
2020-05-21 14:18:23 +00:00
|
|
|
"""
|
|
|
|
calculate bandwith overhead
|
|
|
|
"""
|
2020-05-23 19:36:25 +00:00
|
|
|
paths = self.get_all_paths()
|
2020-05-21 14:18:23 +00:00
|
|
|
lltx = 0
|
|
|
|
llrx = 0
|
2020-05-23 19:36:25 +00:00
|
|
|
_tx = 0
|
|
|
|
_rx = 0
|
2020-05-21 14:18:23 +00:00
|
|
|
for link in links:
|
|
|
|
sessions = link["sessions"]["established"]
|
2020-05-23 19:36:25 +00:00
|
|
|
for sess in sessions:
|
|
|
|
lltx += sess['tx']
|
|
|
|
llrx += sess['rx']
|
2020-05-21 14:18:23 +00:00
|
|
|
for path in paths:
|
2020-05-23 19:36:25 +00:00
|
|
|
_tx += path['txRateCurrent']
|
|
|
|
_rx += path['rxRateCurrent']
|
|
|
|
lltx -= _tx
|
|
|
|
llrx -= _rx
|
|
|
|
if lltx < 0:
|
|
|
|
lltx = 0
|
|
|
|
if llrx < 0:
|
|
|
|
llrx = 0
|
2020-05-21 14:18:23 +00:00
|
|
|
return lltx, llrx
|
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def display_link(self, y_pos, link):
|
|
|
|
""" display links """
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
2020-10-27 19:03:06 +00:00
|
|
|
sessions = link["sessions"]["established"] or []
|
2020-05-23 19:36:25 +00:00
|
|
|
for sess in sessions:
|
|
|
|
y_pos = self.display_link_session(y_pos, sess)
|
|
|
|
return y_pos
|
|
|
|
|
|
|
|
def display_link_session(self, y_pos, sess):
|
|
|
|
""" display link sessions """
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
self.txrate += sess["txRateCurrent"]
|
|
|
|
self.rxrate += sess["rxRateCurrent"]
|
2021-05-01 12:44:37 +00:00
|
|
|
addr = sess['remoteAddr']
|
|
|
|
if geo:
|
|
|
|
ip = addr.split(':')[0]
|
|
|
|
addr += '\t{}'.format(ip_to_flag(ip))
|
2020-05-21 14:18:23 +00:00
|
|
|
self.win.addstr(
|
|
|
|
"{}\t[{}\ttx]\t[{}\trx]".format(
|
2021-05-01 12:44:37 +00:00
|
|
|
addr, self.speed_of(sess["txRateCurrent"]), self.speed_of(sess["rxRateCurrent"])
|
2019-08-12 11:36:23 +00:00
|
|
|
)
|
2020-05-21 14:18:23 +00:00
|
|
|
)
|
2020-05-23 19:36:25 +00:00
|
|
|
if (sess['txMsgQueueSize'] or 0) > 1:
|
|
|
|
self.win.addstr(" [out window: {}]".format(sess['txMsgQueueSize']))
|
|
|
|
if (sess['rxMsgQueueSize'] or 0) > 1:
|
|
|
|
self.win.addstr(" [in window: {}]".format(sess['rxMsgQueueSize']))
|
2020-05-21 14:18:23 +00:00
|
|
|
def display(acks, label, num='acks', dem='packets'):
|
|
|
|
if acks[dem] > 0:
|
|
|
|
self.win.addstr(" [{}: {}]".format(label, round(float(acks[num]) / float(acks[dem]), 2)))
|
2020-05-23 19:36:25 +00:00
|
|
|
if ('recvMACKs' in sess) and ('sendMACKs' in sess):
|
|
|
|
display(sess['sendMACKs'], 'out MACK density')
|
|
|
|
display(sess['recvMACKs'], 'in MACK density')
|
|
|
|
dats = {'recvAcks': 'in acks',
|
|
|
|
'sendAcks': 'out acks',
|
|
|
|
'recvRTX': 'in RTX',
|
|
|
|
'sendRTX': 'out RTX'}
|
|
|
|
for key in dats:
|
|
|
|
val = dats[key]
|
|
|
|
if (key in sess) and (sess[key] > 0):
|
|
|
|
self.win.addstr(" [{}: {}]".format(val, sess[key]))
|
|
|
|
return y_pos
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def display_dht(self, y_pos, data):
|
|
|
|
""" display dht window """
|
|
|
|
y_pos += 2
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("DHT:")
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("introset lookups")
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = self.display_bucket(y_pos, data["pendingIntrosetLookups"])
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.addstr("router lookups")
|
2020-05-23 19:36:25 +00:00
|
|
|
return self.display_bucket(y_pos, data["pendingRouterLookups"])
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def display_bucket(self, y_pos, data):
|
|
|
|
""" display dht bucket """
|
2019-08-12 11:36:23 +00:00
|
|
|
txs = data["tx"]
|
|
|
|
self.win.addstr(" ({} lookups)".format(len(txs)))
|
2020-05-23 19:36:25 +00:00
|
|
|
for transaction in txs:
|
|
|
|
y_pos += 1
|
|
|
|
self.win.move(y_pos, 1)
|
|
|
|
self.win.addstr("search for {}".format(transaction["tx"]["target"]))
|
|
|
|
return y_pos
|
2019-08-12 11:36:23 +00:00
|
|
|
|
|
|
|
def display_data(self):
|
2020-10-27 19:03:06 +00:00
|
|
|
""" draw main window """
|
2019-08-12 11:36:23 +00:00
|
|
|
if self.data is not None:
|
2020-10-27 19:03:06 +00:00
|
|
|
if self.version:
|
|
|
|
self.win.addstr(1, 1, self.version)
|
2019-08-12 11:36:23 +00:00
|
|
|
services = self.data["services"] or {}
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = 3
|
2019-08-12 11:36:23 +00:00
|
|
|
try:
|
2020-05-23 19:36:25 +00:00
|
|
|
y_pos = self.display_links(y_pos, self.data["links"])
|
|
|
|
for key in services:
|
|
|
|
y_pos = self.display_service(y_pos, key, services[key])
|
|
|
|
y_pos = self.display_dht(y_pos, self.data["dht"])
|
2020-10-27 19:03:06 +00:00
|
|
|
except:
|
|
|
|
pass
|
2019-08-12 11:36:23 +00:00
|
|
|
else:
|
|
|
|
self.win.move(1, 1)
|
|
|
|
self.win.addstr("lokinet offline")
|
|
|
|
|
|
|
|
def run(self):
|
2020-05-23 19:36:25 +00:00
|
|
|
""" run mainloop """
|
2020-10-27 19:03:06 +00:00
|
|
|
try:
|
|
|
|
self.version = json.loads(self.rpc("llarp.version"))['result']['version']
|
|
|
|
except:
|
|
|
|
self.version = None
|
2021-05-01 12:44:37 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
while self._run:
|
|
|
|
if self.update_data():
|
|
|
|
self.win.box()
|
|
|
|
self.display_data()
|
|
|
|
elif self._run:
|
|
|
|
self.win.addstr(1, 1, "offline")
|
|
|
|
else:
|
|
|
|
self._close()
|
|
|
|
return
|
2019-08-12 11:36:23 +00:00
|
|
|
self.win.refresh()
|
2020-05-23 19:36:25 +00:00
|
|
|
try:
|
|
|
|
time.sleep(1)
|
|
|
|
except:
|
|
|
|
self._close()
|
|
|
|
return
|
|
|
|
self.win.clear()
|
2019-08-12 11:36:23 +00:00
|
|
|
|
2020-05-23 19:36:25 +00:00
|
|
|
def main():
|
|
|
|
""" main function """
|
2019-08-12 11:36:23 +00:00
|
|
|
mon = Monitor(
|
2020-05-23 19:36:25 +00:00
|
|
|
len(sys.argv) > 1 and sys.argv[1] or "tcp://127.0.0.1:1190"
|
2019-08-12 11:36:23 +00:00
|
|
|
)
|
|
|
|
mon.run()
|
2020-05-23 19:36:25 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|