Skip to content

Commit 2236c2e

Browse files
committed
collect system info
1 parent b09f9a5 commit 2236c2e

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ web_modules/
5353
.rts2_cache_cjs/
5454
.rts2_cache_es/
5555
.rts2_cache_umd/
56+
57+
system_info.json

node_cli.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
import shutil
1515
import time
1616

17+
import psutil
18+
import threading
19+
20+
1721

1822
# Disable WebdriverManager SSL verification.
1923
os.environ['WDM_SSL_VERIFY'] = '0'
@@ -119,6 +123,39 @@
119123
from Framework.deploy_handler import long_poll_handler
120124
from Framework.deploy_handler import adapter
121125

126+
def get_system_info():
127+
while True:
128+
# Current timestamp
129+
current_time = dt.now().strftime('%Y-%m-%d %H:%M:%S')
130+
131+
# Current CPU usage
132+
cpu_usage = psutil.cpu_percent(interval=1)
133+
134+
# Current RAM usage
135+
ram_usage = psutil.virtual_memory().percent
136+
137+
# Top 10 processes with highest CPU usage
138+
top_cpu_processes = [p.info for p in psutil.process_iter(attrs=['pid', 'name', 'cpu_percent'])]
139+
top_cpu_processes = sorted(top_cpu_processes, key=lambda x: x['cpu_percent'], reverse=True)[:10]
140+
141+
# Top 10 processes with highest RAM usage
142+
top_ram_processes = [p.info for p in psutil.process_iter(attrs=['pid', 'name', 'memory_percent'])]
143+
top_ram_processes = sorted(top_ram_processes, key=lambda x: x['memory_percent'], reverse=True)[:10]
144+
145+
data = {
146+
"Timestamp": current_time,
147+
"CPU_Usage": cpu_usage,
148+
"RAM_Usage": ram_usage,
149+
"Top_CPU_Processes": top_cpu_processes,
150+
"Top_RAM_Processes": top_ram_processes
151+
}
152+
153+
# Append data to the JSON file
154+
with open('system_info.json', 'a') as file:
155+
file.write(json.dumps(data, indent=4) + "\n")
156+
157+
time.sleep(5) # Adjust the interval (in seconds) as needed
158+
122159
def signal_handler(sig, frame):
123160
CommonUtil.run_cancelled = True
124161
print("Disconnecting from server...")
@@ -1203,10 +1240,17 @@ def Bypass():
12031240
print("Exiting...")
12041241
sys.exit(1)
12051242

1243+
thread = threading.Thread(target=get_system_info)
1244+
thread.daemon = True
1245+
thread.start()
1246+
12061247
if local_run:
12071248
Local_run(log_dir=log_dir)
12081249
else:
12091250
# Bypass()
12101251
Login(cli=True, run_once=RUN_ONCE, log_dir=log_dir)
1252+
1253+
1254+
12111255
CommonUtil.run_cancelled = True
12121256
CommonUtil.ShutdownExecutor()

0 commit comments

Comments
 (0)