Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ web_modules/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

system_info.json
58 changes: 58 additions & 0 deletions node_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import shutil
import time

import psutil
import threading



# Disable WebdriverManager SSL verification.
os.environ['WDM_SSL_VERIFY'] = '0'
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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()