mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-23 06:00:18 +00:00
Added interface sorting and announce rate display to rnstatus
This commit is contained in:
parent
136713eec1
commit
4fa616a326
@ -46,7 +46,7 @@ def size_str(num, suffix='B'):
|
|||||||
|
|
||||||
return "%.2f%s%s" % (num, last_unit, suffix)
|
return "%.2f%s%s" % (num, last_unit, suffix)
|
||||||
|
|
||||||
def program_setup(configdir, dispall=False, verbosity=0, name_filter=None,json=False):
|
def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=False, astats=False, sorting=None, sort_reverse=False):
|
||||||
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity)
|
||||||
|
|
||||||
stats = None
|
stats = None
|
||||||
@ -62,6 +62,7 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None,json=F
|
|||||||
if isinstance(stats[s], bytes):
|
if isinstance(stats[s], bytes):
|
||||||
stats[s] = RNS.hexrep(stats[s], delimit=False)
|
stats[s] = RNS.hexrep(stats[s], delimit=False)
|
||||||
|
|
||||||
|
if isinstance(stats[s], dict):
|
||||||
for i in stats[s]:
|
for i in stats[s]:
|
||||||
if isinstance(i, dict):
|
if isinstance(i, dict):
|
||||||
for k in i:
|
for k in i:
|
||||||
@ -71,7 +72,26 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None,json=F
|
|||||||
print(json.dumps(stats))
|
print(json.dumps(stats))
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
for ifstat in stats["interfaces"]:
|
interfaces = stats["interfaces"]
|
||||||
|
if sorting != None and isinstance(sorting, str):
|
||||||
|
sorting = sorting.lower()
|
||||||
|
if sorting == "rate" or sorting == "bitrate":
|
||||||
|
interfaces.sort(key=lambda i: i["bitrate"], reverse=not sort_reverse)
|
||||||
|
if sorting == "rx":
|
||||||
|
interfaces.sort(key=lambda i: i["rxb"], reverse=not sort_reverse)
|
||||||
|
if sorting == "tx":
|
||||||
|
interfaces.sort(key=lambda i: i["txb"], reverse=not sort_reverse)
|
||||||
|
if sorting == "traffic":
|
||||||
|
interfaces.sort(key=lambda i: i["rxb"]+i["txb"], reverse=not sort_reverse)
|
||||||
|
if sorting == "announces" or sorting == "announce":
|
||||||
|
interfaces.sort(key=lambda i: i["incoming_announce_frequency"]+i["outgoing_announce_frequency"], reverse=not sort_reverse)
|
||||||
|
if sorting == "arx":
|
||||||
|
interfaces.sort(key=lambda i: i["incoming_announce_frequency"], reverse=not sort_reverse)
|
||||||
|
if sorting == "atx":
|
||||||
|
interfaces.sort(key=lambda i: i["outgoing_announce_frequency"], reverse=not sort_reverse)
|
||||||
|
|
||||||
|
|
||||||
|
for ifstat in interfaces:
|
||||||
name = ifstat["name"]
|
name = ifstat["name"]
|
||||||
|
|
||||||
if dispall or not (
|
if dispall or not (
|
||||||
@ -166,13 +186,17 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None,json=F
|
|||||||
if "i2p_b32" in ifstat and ifstat["i2p_b32"] != None:
|
if "i2p_b32" in ifstat and ifstat["i2p_b32"] != None:
|
||||||
print(" I2P B32 : {ep}".format(ep=str(ifstat["i2p_b32"])))
|
print(" I2P B32 : {ep}".format(ep=str(ifstat["i2p_b32"])))
|
||||||
|
|
||||||
if "announce_queue" in ifstat and ifstat["announce_queue"] != None and ifstat["announce_queue"] > 0:
|
if astats and "announce_queue" in ifstat and ifstat["announce_queue"] != None and ifstat["announce_queue"] > 0:
|
||||||
aqn = ifstat["announce_queue"]
|
aqn = ifstat["announce_queue"]
|
||||||
if aqn == 1:
|
if aqn == 1:
|
||||||
print(" Queued : {np} announce".format(np=aqn))
|
print(" Queued : {np} announce".format(np=aqn))
|
||||||
else:
|
else:
|
||||||
print(" Queued : {np} announces".format(np=aqn))
|
print(" Queued : {np} announces".format(np=aqn))
|
||||||
|
|
||||||
|
if astats and "incoming_announce_frequency" in ifstat and ifstat["incoming_announce_frequency"] != None:
|
||||||
|
print(" Announces : {iaf}↑".format(iaf=RNS.prettyfrequency(ifstat["outgoing_announce_frequency"])))
|
||||||
|
print(" {iaf}↓".format(iaf=RNS.prettyfrequency(ifstat["incoming_announce_frequency"])))
|
||||||
|
|
||||||
print(" Traffic : {txb}↑\n {rxb}↓".format(rxb=size_str(ifstat["rxb"]), txb=size_str(ifstat["txb"])))
|
print(" Traffic : {txb}↑\n {rxb}↓".format(rxb=size_str(ifstat["rxb"]), txb=size_str(ifstat["txb"])))
|
||||||
|
|
||||||
if "transport_id" in stats and stats["transport_id"] != None:
|
if "transport_id" in stats and stats["transport_id"] != None:
|
||||||
@ -200,6 +224,31 @@ def main():
|
|||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-A",
|
||||||
|
"--announce-stats",
|
||||||
|
action="store_true",
|
||||||
|
help="show announce stats",
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-s",
|
||||||
|
"--sort",
|
||||||
|
action="store",
|
||||||
|
help="sort interfaces by [traffic, rx, tx, announces, arx, atx, rate]",
|
||||||
|
default=None,
|
||||||
|
type=str
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-r",
|
||||||
|
"--reverse",
|
||||||
|
action="store_true",
|
||||||
|
help="reverse sorting",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-j",
|
"-j",
|
||||||
"--json",
|
"--json",
|
||||||
@ -219,7 +268,16 @@ def main():
|
|||||||
else:
|
else:
|
||||||
configarg = None
|
configarg = None
|
||||||
|
|
||||||
program_setup(configdir = configarg, dispall = args.all, verbosity=args.verbose, name_filter=args.filter, json=args.json)
|
program_setup(
|
||||||
|
configdir = configarg,
|
||||||
|
dispall = args.all,
|
||||||
|
verbosity=args.verbose,
|
||||||
|
name_filter=args.filter,
|
||||||
|
json=args.json,
|
||||||
|
astats=args.announce_stats,
|
||||||
|
sorting=args.sort,
|
||||||
|
sort_reverse=args.reverse,
|
||||||
|
)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
|
Loading…
Reference in New Issue
Block a user