garvitcoder

script for your2k2026

May 3rd, 2026
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. # Import the psutil library for system information
  2. import psutil
  3. import time
  4.  
  5. def system_monitor(interval=5):
  6. """
  7. Monitors CPU, memory, and disk usage.
  8. interval: time in seconds between updates
  9. """
  10. while True:
  11. # CPU usage percentage over 1 second
  12. cpu = psutil.cpu_percent(interval=1)
  13.  
  14. # Memory usage details
  15. memory = psutil.virtual_memory()
  16.  
  17. # Disk usage details for root directory
  18. disk = psutil.disk_usage('/')
  19.  
  20. # Print results in a clean format
  21. print("="*40)
  22. print(f"CPU Usage: {cpu}%")
  23. print(f"Memory Usage: {memory.percent}% "
  24. f"({memory.used // (1024**2)} MB / {memory.total // (1024**2)} MB)")
  25. print(f"Disk Usage: {disk.percent}% "
  26. f"({disk.used // (1024**3)} GB / {disk.total // (1024**3)} GB)")
  27. print("="*40)
  28.  
  29. # Wait before repeating
  30. time.sleep(interval)
  31.  
  32. if __name__ == "__main__":
  33. # Run the monitor with updates every 5 seconds
  34. system_monitor(interval=5)
Advertisement
Add Comment
Please, Sign In to add comment