import psutil
|
|
import time
|
|
|
|
try:
|
|
with open('usage.log', 'a') as log_file:
|
|
while True:
|
|
cpu = psutil.cpu_percent(interval=1)
|
|
memory = psutil.virtual_memory().percent
|
|
log_entry = f"CPU: {cpu}%, Memory: {memory}%\n"
|
|
log_file.write(log_entry)
|
|
log_file.flush()
|
|
time.sleep(4)
|
|
except KeyboardInterrupt:
|
|
print('Monitoring stopped by user.') |