55 lines
2.0 MiB
Plaintext
55 lines
2.0 MiB
Plaintext
|
|
TASK: Write a Python script 'system_monitor.py' that logs CPU and memory usage to 'usage.log' every 5 seconds. Ensure it handles keyboard interrupts.
|
|||
|
|
----------------------------------------
|
|||
|
|
Loading...
|
|||
|
|
|
|||
|
|
[Agent] Iteration 1/300
|
|||
|
|
[Agent] has_tool_calls=true
|
|||
|
|
[Agent] Executing 1 tool(s)
|
|||
|
|
-> Writing file: system_monitor.py
|
|||
|
|
[2m[parallel] launching write_file[0m
|
|||
|
|
|
|||
|
|
[36m [2m CHANGES: system_monitor.py [0m
|
|||
|
|
LINE OLD
|
|||
|
|
--------------------------------------------------------------------------------------------------------------------------------------------
|
|||
|
|
1 import psutil
|
|||
|
|
2 import time
|
|||
|
|
3 [31m-[0m [31mimport logging
|
|||
|
|
4
|
|||
|
|
5 [31m-[0m [31m# Configure logging
|
|||
|
|
6 [31m-[0m [31mlogging.basicConfig(filename='usage.log', level=logging.INFO, format='%(asctime)s - %(message)s')
|
|||
|
|
|
|||
|
|
|
|||
|
|
7
|
|||
|
|
8 try:
|
|||
|
|
9 [31m-[0m [31m while True:
|
|||
|
|
10 [31m-[0m [31m cpu_usage = psutil.cpu_percent(interval=1)
|
|||
|
|
11 [31m-[0m [31m mem = psutil.virtual_memory()
|
|||
|
|
12 [31m-[0m [31m mem_usage = mem.percent
|
|||
|
|
13 [31m-[0m [31m log_message = f"CPU Usage: {cpu_usage}%, Memory Usage: {mem_usage}%"
|
|||
|
|
14 [31m-[0m [31m print(log_message)
|
|||
|
|
15 [31m-[0m [31m logging.info(log_message)
|
|||
|
|
16 [31m-[0m [31m time.sleep(4)
|
|||
|
|
17 [31m-[0m [31mexcept KeyboardInterrupt:
|
|||
|
|
18 [31m-[0m [31m print("Monitoring stopped by user.")
|
|||
|
|
19 [31m-[0m [31m pass
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
[Agent] Iteration 2/300
|
|||
|
|
The script [33msystem_monitor.py[0m has been created. It logs CPU and memory usage to [33musage.log[0m every 5 seconds and handles keyboard interrupts gracefully. Would you like to review or run this script?
|
|||
|
|
[Agent] has_tool_calls=false
|
|||
|
|
[Agent] Response indicates incomplete work, auto-continuing
|
|||
|
|
[Agent] Iteration 3/300
|
|||
|
|
The script [33msystem_monitor.py[0m has been successfully created. You can now run it to start logging CPU and memory usage every 5 seconds. Would you like me to execute the script for you or provide instructions on how to run it?
|
|||
|
|
[Agent] has_tool_calls=false
|
|||
|
|
[Agent] Completed in 3 iteration(s)
|