From 2236c2ec4dad74ef870efe8f2af226e20f36f1f9 Mon Sep 17 00:00:00 2001 From: Sakib Date: Wed, 8 Nov 2023 14:29:41 +0600 Subject: [PATCH 1/3] collect system info --- .gitignore | 2 ++ node_cli.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/.gitignore b/.gitignore index 1cf824fc6..705c64212 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,5 @@ web_modules/ .rts2_cache_cjs/ .rts2_cache_es/ .rts2_cache_umd/ + +system_info.json \ No newline at end of file diff --git a/node_cli.py b/node_cli.py index fdb02fed1..5737b4720 100755 --- a/node_cli.py +++ b/node_cli.py @@ -14,6 +14,10 @@ import shutil import time +import psutil +import threading + + # Disable WebdriverManager SSL verification. os.environ['WDM_SSL_VERIFY'] = '0' @@ -119,6 +123,39 @@ from Framework.deploy_handler import long_poll_handler from Framework.deploy_handler import adapter +def get_system_info(): + while True: + # Current timestamp + current_time = dt.now().strftime('%Y-%m-%d %H:%M:%S') + + # Current CPU usage + cpu_usage = psutil.cpu_percent(interval=1) + + # Current RAM usage + ram_usage = psutil.virtual_memory().percent + + # Top 10 processes with highest CPU usage + top_cpu_processes = [p.info for p in psutil.process_iter(attrs=['pid', 'name', 'cpu_percent'])] + top_cpu_processes = sorted(top_cpu_processes, key=lambda x: x['cpu_percent'], reverse=True)[:10] + + # Top 10 processes with highest RAM usage + top_ram_processes = [p.info for p in psutil.process_iter(attrs=['pid', 'name', 'memory_percent'])] + top_ram_processes = sorted(top_ram_processes, key=lambda x: x['memory_percent'], reverse=True)[:10] + + data = { + "Timestamp": current_time, + "CPU_Usage": cpu_usage, + "RAM_Usage": ram_usage, + "Top_CPU_Processes": top_cpu_processes, + "Top_RAM_Processes": top_ram_processes + } + + # Append data to the JSON file + with open('system_info.json', 'a') as file: + file.write(json.dumps(data, indent=4) + "\n") + + time.sleep(5) # Adjust the interval (in seconds) as needed + def signal_handler(sig, frame): CommonUtil.run_cancelled = True print("Disconnecting from server...") @@ -1203,10 +1240,17 @@ def Bypass(): print("Exiting...") sys.exit(1) + thread = threading.Thread(target=get_system_info) + thread.daemon = True + thread.start() + if local_run: Local_run(log_dir=log_dir) else: # Bypass() Login(cli=True, run_once=RUN_ONCE, log_dir=log_dir) + + + CommonUtil.run_cancelled = True CommonUtil.ShutdownExecutor() From fc694dbe6f1ed762aee95f340a4c22772ddcda83 Mon Sep 17 00:00:00 2001 From: Sakib Date: Sun, 19 Nov 2023 14:11:07 +0600 Subject: [PATCH 2/3] added datetime in decorator --- Framework/Utilities/decorators.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Framework/Utilities/decorators.py b/Framework/Utilities/decorators.py index 8aef51fb1..6cbd34790 100644 --- a/Framework/Utilities/decorators.py +++ b/Framework/Utilities/decorators.py @@ -1,7 +1,9 @@ import time import functools from . import CommonUtil +from datetime import datetime +datetime_format = "%d-%b-%Y %H:%M:%S" def logger(func): """Log the entry and exit of the decorated function""" @@ -9,7 +11,7 @@ def logger(func): @functools.wraps(func) def wrapper(*args, **kwargs): start_time = time.perf_counter() - CommonUtil.ExecLog(None, f"Entering into function: {func.__name__!r}.", 5) + CommonUtil.ExecLog(None, f"{datetime.now().strftime(datetime_format)} | Entering into function: {func.__name__!r}.", 5) result = func(*args, **kwargs) end_time = time.perf_counter() @@ -17,7 +19,7 @@ def wrapper(*args, **kwargs): CommonUtil.ExecLog( None, - f"Exited from function: {func.__name__!r}. Runtime: {run_time:.4f} secs.", + f"{datetime.now().strftime(datetime_format)} | Exited from function: {func.__name__!r}. Runtime: {run_time:.4f} secs.", 5, ) From 1dd6ac8a86b930eba3bdecc10063f76e51fb2e3c Mon Sep 17 00:00:00 2001 From: Sakib Date: Sun, 19 Nov 2023 14:16:39 +0600 Subject: [PATCH 3/3] Revert "collect system info" This reverts commit 2236c2ec4dad74ef870efe8f2af226e20f36f1f9. --- .gitignore | 2 -- node_cli.py | 44 -------------------------------------------- 2 files changed, 46 deletions(-) diff --git a/.gitignore b/.gitignore index 705c64212..1cf824fc6 100644 --- a/.gitignore +++ b/.gitignore @@ -53,5 +53,3 @@ web_modules/ .rts2_cache_cjs/ .rts2_cache_es/ .rts2_cache_umd/ - -system_info.json \ No newline at end of file diff --git a/node_cli.py b/node_cli.py index 5737b4720..fdb02fed1 100755 --- a/node_cli.py +++ b/node_cli.py @@ -14,10 +14,6 @@ import shutil import time -import psutil -import threading - - # Disable WebdriverManager SSL verification. os.environ['WDM_SSL_VERIFY'] = '0' @@ -123,39 +119,6 @@ from Framework.deploy_handler import long_poll_handler from Framework.deploy_handler import adapter -def get_system_info(): - while True: - # Current timestamp - current_time = dt.now().strftime('%Y-%m-%d %H:%M:%S') - - # Current CPU usage - cpu_usage = psutil.cpu_percent(interval=1) - - # Current RAM usage - ram_usage = psutil.virtual_memory().percent - - # Top 10 processes with highest CPU usage - top_cpu_processes = [p.info for p in psutil.process_iter(attrs=['pid', 'name', 'cpu_percent'])] - top_cpu_processes = sorted(top_cpu_processes, key=lambda x: x['cpu_percent'], reverse=True)[:10] - - # Top 10 processes with highest RAM usage - top_ram_processes = [p.info for p in psutil.process_iter(attrs=['pid', 'name', 'memory_percent'])] - top_ram_processes = sorted(top_ram_processes, key=lambda x: x['memory_percent'], reverse=True)[:10] - - data = { - "Timestamp": current_time, - "CPU_Usage": cpu_usage, - "RAM_Usage": ram_usage, - "Top_CPU_Processes": top_cpu_processes, - "Top_RAM_Processes": top_ram_processes - } - - # Append data to the JSON file - with open('system_info.json', 'a') as file: - file.write(json.dumps(data, indent=4) + "\n") - - time.sleep(5) # Adjust the interval (in seconds) as needed - def signal_handler(sig, frame): CommonUtil.run_cancelled = True print("Disconnecting from server...") @@ -1240,17 +1203,10 @@ def Bypass(): print("Exiting...") sys.exit(1) - thread = threading.Thread(target=get_system_info) - thread.daemon = True - thread.start() - if local_run: Local_run(log_dir=log_dir) else: # Bypass() Login(cli=True, run_once=RUN_ONCE, log_dir=log_dir) - - - CommonUtil.run_cancelled = True CommonUtil.ShutdownExecutor()