14 lines
418 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:
2026-01-29 08:06:31 +01:00
cpu = psutil.cpu_percent(interval=1)
2026-02-10 04:29:48 +01:00
memory = psutil.virtual_memory().percent
log_entry = f"CPU: {cpu}%, Memory: {memory}%\n"
2026-01-29 07:42:06 +01:00
log_file.write(log_entry)
log_file.flush()
2026-02-10 04:29:48 +01:00
time.sleep(4)
2026-01-29 06:54:10 +01:00
except KeyboardInterrupt:
2026-02-10 04:29:48 +01:00
print('Monitoring stopped by user.')