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 5459cf1d0..434a5670a 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,53 @@ 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', 'r+') as file: + try: + existing_data = json.load(file) + except json.decoder.JSONDecodeError: + existing_data = [] + + # Filter out data older than 3 days + existing_data = [entry for entry in existing_data if dt.strptime(entry['Timestamp'], '%Y-%m-%d %H:%M:%S') >= dt.now() - datetime.timedelta(days=3)] + + # Append new data + existing_data.append(data) + + # Reset file pointer and write back to the file + file.seek(0) + file.truncate() + json.dump(existing_data, file, indent=4) + + time.sleep(5) # Adjust the interval (in seconds) as needed + def signal_handler(sig, frame): CommonUtil.run_cancelled = True print("Disconnecting from server...") @@ -1201,10 +1252,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()