From 4d29b18284bef8c64a478a9ad9eea9eaec41d16a Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 10:45:12 +0100 Subject: [PATCH 01/17] commented out wall of shame and channel directory --- command_handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index 739fb2a..207b639 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -47,8 +47,8 @@ def handle_help_command(sender_id, interface, state=None): "[B]ulletin Menu", "[S]tats Menu", "[F]ortune", - "[W]all of Shame", - "[C]hannel Directory", + #"[W]all of Shame", + #"[C]hannel Directory", "EXIT: Exit current menu", "[H]elp" ] From 1462e91a8fd81dab0c9c8ad9ba147c84eeac75c0 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 10:46:36 +0100 Subject: [PATCH 02/17] Commented out EXIT from help menu as not really needed and adding to the message size --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 207b639..bf6bc41 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -49,7 +49,7 @@ def handle_help_command(sender_id, interface, state=None): "[F]ortune", #"[W]all of Shame", #"[C]hannel Directory", - "EXIT: Exit current menu", + #"EXIT: Exit current menu", "[H]elp" ] if state and 'command' in state: From 230499fc9d2a50c1c2191b3e27d3efc830a0bc4b Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:00:38 +0100 Subject: [PATCH 03/17] In itial work to menu system to add server stats --- command_handlers.py | 75 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index bf6bc41..0c6f14e 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -70,17 +70,21 @@ def handle_help_command(sender_id, interface, state=None): ] elif current_command == 'STATS': commands = [ - "[0]Total Nodes", - "[1]Total HW Models", - "[2]Total Roles", - "[3]Back" + "[0]Mesh Stats", + "[1]Server Stats", + "[2]Exit Stats Menu" +# "[0]Total Nodes", +# "[1]Total HW Models", +# "[2]Total Roles", +# "[3]Back" ] response = title + "Available commands:\n" + "\n".join(commands) send_message(response, sender_id, interface) def handle_stats_command(sender_id, interface): - response = "What stats would you like to view?\n\n[0]Node Numbers\n[1]Hardware\n[2]Roles\n[3]Main Menu" + response = "What stats would you like to view?\n\n[0]Mesh Stats\n[1]Server Stats\n[2]Exit Stats Menu" +# response = "What stats would you like to view?\n\n[0]Node Numbers\n[1]Hardware\n[2]Roles\n[3]Main Menu" send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 1}) @@ -100,12 +104,17 @@ def handle_fortune_command(sender_id, interface): def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): - if step == 1: - choice = message.upper() - if choice == '3': + if step == 1: + choice = int(choice) + if choice == 2: handle_help_command(sender_id, interface) return + + elif step == 2: choice = int(choice) + if choice == 3: + handle_help_command(sender_id, interface) + return if choice == 0: response = "Select time period for total nodes:\n\n[0]ALL\n[1]Last 24 Hours\n[2]Last 8 Hours\n[3]Last Hour" send_message(response, sender_id, interface) @@ -127,7 +136,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) - elif step == 2: + elif step == 3: choice = int(message) current_time = int(time.time()) if choice == 0: @@ -147,6 +156,54 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): handle_stats_steps(sender_id, '0', 1, interface, bbs_nodes) +#def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): +# if step == 1: +# choice = message.upper() +# if choice == '3': +# handle_help_command(sender_id, interface) +# return +# choice = int(choice) +# if choice == 0: +# response = "Select time period for total nodes:\n\n[0]ALL\n[1]Last 24 Hours\n[2]Last 8 Hours\n[3]Last Hour" +# send_message(response, sender_id, interface) +# update_user_state(sender_id, {'command': 'STATS', 'step': 2}) +# elif choice == 1: +# hw_models = {} +# for node in interface.nodes.values(): +# hw_model = node['user'].get('hwModel', 'Unknown') +# hw_models[hw_model] = hw_models.get(hw_model, 0) + 1 +# response = "Hardware Models:\n" + "\n".join([f"{model}: {count}" for model, count in hw_models.items()]) +# send_message(response, sender_id, interface) +# handle_stats_command(sender_id, interface) +# elif choice == 2: +# roles = {} +# for node in interface.nodes.values(): +# role = node['user'].get('role', 'Unknown') +# roles[role] = roles.get(role, 0) + 1 +# response = "Roles:\n" + "\n".join([f"{role}: {count}" for role, count in roles.items()]) +# send_message(response, sender_id, interface) +# handle_stats_command(sender_id, interface) + +# elif step == 2: +# choice = int(message) +# current_time = int(time.time()) +# if choice == 0: +# total_nodes = len(interface.nodes) +# send_message(f"Total nodes seen: {total_nodes}", sender_id, interface) +# else: +# time_limits = [86400, 28800, 3600] # Last 24 hours, Last 8 hours, Last hour +# time_limit = current_time - time_limits[choice - 1] +# total_nodes = 0 +# for node in interface.nodes.values(): +# last_heard = node.get('lastHeard', 0) +# if last_heard is not None and last_heard >= time_limit: +# total_nodes += 1 +# logging.info(f"Node {node.get('user', {}).get('longName', 'Unknown')} heard at {last_heard}, within limit {time_limit}") +# timeframes = ["24 hours", "8 hours", "hour"] +# send_message(f"Total nodes seen in the last {timeframes[choice - 1]}: {total_nodes}", sender_id, interface) +# handle_stats_steps(sender_id, '0', 1, interface, bbs_nodes) + + def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes): boards = {0: "General", 1: "Info", 2: "News", 3: "Urgent"} From d87f8793915a9c84d103337ca316655a6c4ecc13 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:03:56 +0100 Subject: [PATCH 04/17] Fixed stats steps --- command_handlers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index 0c6f14e..e27bbd8 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -105,13 +105,12 @@ def handle_fortune_command(sender_id, interface): def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): if step == 1: - choice = int(choice) + choice = int(message) if choice == 2: handle_help_command(sender_id, interface) return elif step == 2: - choice = int(choice) if choice == 3: handle_help_command(sender_id, interface) return From 8387b9d5aacfcb1c8713a2cd83b9343dc236e0d9 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:10:55 +0100 Subject: [PATCH 05/17] More stats menu work to incorporste server stats --- command_handlers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/command_handlers.py b/command_handlers.py index e27bbd8..f5e9843 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -109,6 +109,15 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): if choice == 2: handle_help_command(sender_id, interface) return + if choice == 0: + response = "What stats would you like to view?\n\n[0]Node Numbers\n[1]Hardware\n[2]Roles\n[3]Main Menu" + send_message(response, sender_id, interface) + update_user_state(sender_id, {'command': 'STATS', 'step': 2}) + if choice == 1: + response = "COMING SOON!!" + send_message(response, sender_id, interface) + handle_help_command(sender_id, interface) + return elif step == 2: if choice == 3: From f4424e9aa9910b6cdc7733e4a221a105a94d6726 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:12:31 +0100 Subject: [PATCH 06/17] fixed missing variable in stats menu --- command_handlers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/command_handlers.py b/command_handlers.py index f5e9843..7c5d267 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -120,6 +120,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): return elif step == 2: + choice = int(message) if choice == 3: handle_help_command(sender_id, interface) return From c872e365558435c76e67317de067969e85ffb1fe Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:18:14 +0100 Subject: [PATCH 07/17] more stats menu work --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 7c5d267..d24f88f 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -116,7 +116,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): if choice == 1: response = "COMING SOON!!" send_message(response, sender_id, interface) - handle_help_command(sender_id, interface) + handle_stats_command(sender_id, interface) return elif step == 2: From b739a1e7278d788406308a5e0cabfc2aac779179 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:25:15 +0100 Subject: [PATCH 08/17] added psutil library --- command_handlers.py | 1 + requirements.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/command_handlers.py b/command_handlers.py index d24f88f..25c440e 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -1,6 +1,7 @@ import logging import random import time +import psutil from config_init import initialize_config from db_operations import ( diff --git a/requirements.txt b/requirements.txt index d51a371..5930f60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ meshtastic pypubsub +psutil \ No newline at end of file From 29ab89ca137e0e378b8fc458f26790a69613e2ed Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:29:50 +0100 Subject: [PATCH 09/17] adding server stats --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 25c440e..3a8ccae 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -115,7 +115,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: - response = "COMING SOON!!" + response = "CPU: " + psutil.cpu_percent() send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From b58d22cefc517014418ee762700bba3714c71901 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:33:05 +0100 Subject: [PATCH 10/17] adding server stats stuff --- command_handlers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index 3a8ccae..e25c6e4 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -115,7 +115,8 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: - response = "CPU: " + psutil.cpu_percent() + cpu = psutil.cpu_percent() + response = "CPU: " + print(cpu) send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From 20079d416cd49b626ddccc62395ec6b96b2b136d Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:35:55 +0100 Subject: [PATCH 11/17] testing server stats --- command_handlers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index e25c6e4..84a8d5c 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -116,7 +116,8 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: cpu = psutil.cpu_percent() - response = "CPU: " + print(cpu) + response = "CPU: " + print(cpu) send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From 75c29b950f6a96769eebdb22e7b40398c96a152e Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:38:14 +0100 Subject: [PATCH 12/17] still trying to get server stats to cooperate --- command_handlers.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index 84a8d5c..d4105fe 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -115,9 +115,8 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: - cpu = psutil.cpu_percent() - response = "CPU: " - print(cpu) + cpu = print(psutil.cpu_percent()) + response = "CPU: " + cpu + "%" send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From 47db647b2e4c2414839e3574ce86d9a6ef8e00cb Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:44:28 +0100 Subject: [PATCH 13/17] still working on getting server stats working --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index d4105fe..2f50b05 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -116,7 +116,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: cpu = print(psutil.cpu_percent()) - response = "CPU: " + cpu + "%" + response = "CPU: " + str(cpu) + "%" send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From a02534d90d401c9dfa5ed6349c8e3e61aee02119 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:48:17 +0100 Subject: [PATCH 14/17] trying to make server stats working --- command_handlers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index 2f50b05..6e25404 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -115,8 +115,8 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: - cpu = print(psutil.cpu_percent()) - response = "CPU: " + str(cpu) + "%" + cpu = str(psutil.cpu_percent()) + response = "CPU: " + cpu + "%" send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) return From dfc8ca6431a756d7d4305b1ae957fde70da18b85 Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:51:44 +0100 Subject: [PATCH 15/17] fix for server stats psutil cpu% --- command_handlers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/command_handlers.py b/command_handlers.py index 6e25404..a66c944 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -115,6 +115,8 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 2}) if choice == 1: + psutil.cpu_percent() + time.sleep(0.1) cpu = str(psutil.cpu_percent()) response = "CPU: " + cpu + "%" send_message(response, sender_id, interface) From eabc6b708bc637e4d6880ba9defade748766398a Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:56:01 +0100 Subject: [PATCH 16/17] fix for multi core utilisation display stats menu --- command_handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command_handlers.py b/command_handlers.py index a66c944..bb5cae7 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -117,7 +117,7 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): if choice == 1: psutil.cpu_percent() time.sleep(0.1) - cpu = str(psutil.cpu_percent()) + cpu = str(psutil.cpu_percent()/psutil.cpu_count()) response = "CPU: " + cpu + "%" send_message(response, sender_id, interface) handle_stats_command(sender_id, interface) From 3e4a51c1ec71d16367be51ee4eb516c120c61ccd Mon Sep 17 00:00:00 2001 From: Blergo Date: Tue, 2 Jul 2024 11:59:50 +0100 Subject: [PATCH 17/17] Tidy up unused code --- command_handlers.py | 53 --------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/command_handlers.py b/command_handlers.py index bb5cae7..284a39f 100644 --- a/command_handlers.py +++ b/command_handlers.py @@ -74,10 +74,6 @@ def handle_help_command(sender_id, interface, state=None): "[0]Mesh Stats", "[1]Server Stats", "[2]Exit Stats Menu" -# "[0]Total Nodes", -# "[1]Total HW Models", -# "[2]Total Roles", -# "[3]Back" ] response = title + "Available commands:\n" + "\n".join(commands) send_message(response, sender_id, interface) @@ -85,7 +81,6 @@ def handle_help_command(sender_id, interface, state=None): def handle_stats_command(sender_id, interface): response = "What stats would you like to view?\n\n[0]Mesh Stats\n[1]Server Stats\n[2]Exit Stats Menu" -# response = "What stats would you like to view?\n\n[0]Node Numbers\n[1]Hardware\n[2]Roles\n[3]Main Menu" send_message(response, sender_id, interface) update_user_state(sender_id, {'command': 'STATS', 'step': 1}) @@ -169,54 +164,6 @@ def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): handle_stats_steps(sender_id, '0', 1, interface, bbs_nodes) -#def handle_stats_steps(sender_id, message, step, interface, bbs_nodes): -# if step == 1: -# choice = message.upper() -# if choice == '3': -# handle_help_command(sender_id, interface) -# return -# choice = int(choice) -# if choice == 0: -# response = "Select time period for total nodes:\n\n[0]ALL\n[1]Last 24 Hours\n[2]Last 8 Hours\n[3]Last Hour" -# send_message(response, sender_id, interface) -# update_user_state(sender_id, {'command': 'STATS', 'step': 2}) -# elif choice == 1: -# hw_models = {} -# for node in interface.nodes.values(): -# hw_model = node['user'].get('hwModel', 'Unknown') -# hw_models[hw_model] = hw_models.get(hw_model, 0) + 1 -# response = "Hardware Models:\n" + "\n".join([f"{model}: {count}" for model, count in hw_models.items()]) -# send_message(response, sender_id, interface) -# handle_stats_command(sender_id, interface) -# elif choice == 2: -# roles = {} -# for node in interface.nodes.values(): -# role = node['user'].get('role', 'Unknown') -# roles[role] = roles.get(role, 0) + 1 -# response = "Roles:\n" + "\n".join([f"{role}: {count}" for role, count in roles.items()]) -# send_message(response, sender_id, interface) -# handle_stats_command(sender_id, interface) - -# elif step == 2: -# choice = int(message) -# current_time = int(time.time()) -# if choice == 0: -# total_nodes = len(interface.nodes) -# send_message(f"Total nodes seen: {total_nodes}", sender_id, interface) -# else: -# time_limits = [86400, 28800, 3600] # Last 24 hours, Last 8 hours, Last hour -# time_limit = current_time - time_limits[choice - 1] -# total_nodes = 0 -# for node in interface.nodes.values(): -# last_heard = node.get('lastHeard', 0) -# if last_heard is not None and last_heard >= time_limit: -# total_nodes += 1 -# logging.info(f"Node {node.get('user', {}).get('longName', 'Unknown')} heard at {last_heard}, within limit {time_limit}") -# timeframes = ["24 hours", "8 hours", "hour"] -# send_message(f"Total nodes seen in the last {timeframes[choice - 1]}: {total_nodes}", sender_id, interface) -# handle_stats_steps(sender_id, '0', 1, interface, bbs_nodes) - - def handle_bb_steps(sender_id, message, step, state, interface, bbs_nodes): boards = {0: "General", 1: "Info", 2: "News", 3: "Urgent"}