mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-15 12:51:57 -05:00
Populate stats object with threads info
This patch adds the thread names and state to the stats object so the aprsd fetch-stats command can show it.
This commit is contained in:
parent
0a14b07fae
commit
191e1ff552
@ -53,7 +53,7 @@ def fetch_stats(ctx, ip_address, port, magic_word):
|
||||
with console.status(msg) as status:
|
||||
client = rpc_client.RPCClient(ip_address, port, magic_word)
|
||||
stats = client.get_stats_dict()
|
||||
# console.print_json(data=stats)
|
||||
console.print_json(data=stats)
|
||||
aprsd_title = (
|
||||
"APRSD "
|
||||
f"[bold cyan]v{stats['aprsd']['version']}[/] "
|
||||
@ -76,6 +76,13 @@ def fetch_stats(ctx, ip_address, port, magic_word):
|
||||
table.add_row(key, value)
|
||||
console.print(table)
|
||||
|
||||
threads_table = Table(title="Threads")
|
||||
threads_table.add_column("Name")
|
||||
threads_table.add_column("Alive?")
|
||||
for name, alive in stats["aprsd"]["threads"].items():
|
||||
threads_table.add_row(name, str(alive))
|
||||
|
||||
console.print(threads_table)
|
||||
|
||||
msgs_table = Table(title="Messages")
|
||||
msgs_table.add_column("Key")
|
||||
@ -85,14 +92,25 @@ def fetch_stats(ctx, ip_address, port, magic_word):
|
||||
|
||||
console.print(msgs_table)
|
||||
|
||||
packets_table = Table(title="Packets")
|
||||
packets_table.add_column("Key")
|
||||
packets_table.add_column("Value")
|
||||
for key, value in stats["packets"].items():
|
||||
packets_table.add_row(key, str(value))
|
||||
packet_totals = Table(title="Packet Totals")
|
||||
packet_totals.add_column("Key")
|
||||
packet_totals.add_column("Value")
|
||||
packet_totals.add_row("Total Received", str(stats["packets"]["total_received"]))
|
||||
packet_totals.add_row("Total Sent", str(stats["packets"]["total_sent"]))
|
||||
packet_totals.add_row("Total Tracked", str(stats["packets"]["total_tracked"]))
|
||||
console.print(packet_totals)
|
||||
|
||||
# Show each of the packet types
|
||||
packets_table = Table(title="Packets By Type")
|
||||
packets_table.add_column("Packet Type")
|
||||
packets_table.add_column("TX")
|
||||
packets_table.add_column("RX")
|
||||
for key, value in stats["packets"]["by_type"].items():
|
||||
packets_table.add_row(key, str(value["tx"]), str(value["rx"]))
|
||||
|
||||
console.print(packets_table)
|
||||
|
||||
|
||||
if "plugins" in stats:
|
||||
count = len(stats["plugins"])
|
||||
plugins_table = Table(title=f"Plugins ({count})")
|
||||
|
@ -29,6 +29,8 @@ class APRSDStats:
|
||||
_mem_current = 0
|
||||
_mem_peak = 0
|
||||
|
||||
_thread_info = {}
|
||||
|
||||
_pkt_cnt = {
|
||||
"Packet": {
|
||||
"tx": 0,
|
||||
@ -95,6 +97,15 @@ class APRSDStats:
|
||||
def set_memory_peak(self, memory):
|
||||
self._mem_peak = memory
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
def set_thread_info(self, thread_info):
|
||||
self._thread_info = thread_info
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
@property
|
||||
def thread_info(self):
|
||||
return self._thread_info
|
||||
|
||||
@wrapt.synchronized(lock)
|
||||
@property
|
||||
def aprsis_server(self):
|
||||
@ -207,6 +218,7 @@ class APRSDStats:
|
||||
"memory_current_str": utils.human_size(self.memory),
|
||||
"memory_peak": int(self.memory_peak),
|
||||
"memory_peak_str": utils.human_size(self.memory_peak),
|
||||
"threads": self._thread_info,
|
||||
"watch_list": wl.get_all(),
|
||||
"seen_list": sl.get_all(),
|
||||
},
|
||||
@ -216,9 +228,10 @@ class APRSDStats:
|
||||
"last_update": last_aprsis_keepalive,
|
||||
},
|
||||
"packets": {
|
||||
"tracked": int(pl.total_tx() + pl.total_rx()),
|
||||
"sent": int(pl.total_tx()),
|
||||
"received": int(pl.total_rx()),
|
||||
"total_tracked": int(pl.total_tx() + pl.total_rx()),
|
||||
"total_sent": int(pl.total_tx()),
|
||||
"total_received": int(pl.total_rx()),
|
||||
"by_type": self._pkt_cnt,
|
||||
},
|
||||
"messages": {
|
||||
"sent": self._pkt_cnt["MessagePacket"]["tx"],
|
||||
@ -234,6 +247,7 @@ class APRSDStats:
|
||||
"plugins": plugin_stats,
|
||||
}
|
||||
LOG.debug(f"STATS = {stats}")
|
||||
LOG.info("APRSD Stats: DONE")
|
||||
return stats
|
||||
|
||||
def __str__(self):
|
||||
|
@ -65,12 +65,15 @@ class KeepAliveThread(APRSDThread):
|
||||
)
|
||||
LOG.info(keepalive)
|
||||
thread_out = []
|
||||
thread_info = {}
|
||||
for thread in thread_list.threads_list:
|
||||
alive = thread.is_alive()
|
||||
thread_out.append(f"{thread.__class__.__name__}:{alive}")
|
||||
thread_info[thread.__class__.__name__] = alive
|
||||
if not alive:
|
||||
LOG.error(f"Thread {thread}")
|
||||
LOG.info(",".join(thread_out))
|
||||
stats_obj.set_thread_info(thread_info)
|
||||
|
||||
# check the APRS connection
|
||||
cl = client.factory.create()
|
||||
|
Loading…
Reference in New Issue
Block a user