15 lines
429 B
Python
Raw Normal View History

2026-01-29 06:54:10 +01:00
import psutil
import time
try:
2026-01-29 07:42:06 +01:00
with open('usage.log', 'a') as log_file:
2026-01-29 06:54:10 +01:00
while True:
cpu_percent = psutil.cpu_percent(interval=1)
mem = psutil.virtual_memory()
log_entry = f"CPU: {cpu_percent}%, Memory: {mem.percent}%\n"
2026-01-29 07:42:06 +01:00
log_file.write(log_entry)
log_file.flush()
time.sleep(4)
2026-01-29 06:54:10 +01:00
except KeyboardInterrupt:
2026-01-29 07:42:06 +01:00
print("Monitoring stopped by user.")