Advertisement
Python253

pico_mem_monitor

Mar 2nd, 2024 (edited)
1,311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: pico_mem_monitor.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. Pico Mem Monitor: Raspberry Pi Pico Memory Monitoring Script
  8.  
  9. Description:
  10. This script monitors and displays the real-time usage of CPU and memory on a Raspberry Pi Pico. It provides a visual representation of the usage percentages using ASCII bars, making it easy for users to gauge system resource utilization.
  11.  
  12. Usage:
  13. 1. Ensure you have the necessary dependencies installed (psutil library).
  14. 2. Run the script on your Raspberry Pi Pico.
  15. 3. Observe the dynamic updates of CPU and memory usage with corresponding ASCII bars.
  16.  
  17. Features:
  18. - Real-time monitoring of CPU and memory usage.
  19. - Visual representation with ASCII bars for quick interpretation.
  20. - Continuously updates every 0.5 seconds to provide live feedback.
  21.  
  22. Requirements:
  23. - psutil library. Install using 'pip install psutil'.
  24.  
  25. Note: This script is specifically designed for Raspberry Pi Pico. Ensure dependencies are met before execution.
  26.  
  27. Enjoy monitoring the resource utilization of your Raspberry Pi Pico with this simple and informative script!
  28. """
  29. import time
  30. import psutil
  31.  
  32. def display_usage(cpu_usage, mem_usage, bars=50):
  33.     cpu_percent = (cpu_usage / 100.0)
  34.     cpu_bar = '█' * int(cpu_percent * bars) + '-' * (bars - int(cpu_percent * bars))
  35.    
  36.     mem_percent = (mem_usage / 100.0)
  37.     mem_bar = '█' * int(mem_percent * bars) + '-' * (bars - int(mem_percent * bars))
  38.    
  39.     print(f"\rCPU USAGE:  |{cpu_bar}| {cpu_usage:.2f}%  ", end="")
  40.     print(f"\MEM USAGE:  |{mem_bar}| {mem_usage:.2f}%  ", end="\r")
  41.    
  42.  
  43. while True:
  44.     display_usage(psutil.cpu_percent(), psutil.virtual_memory().percent, 30)
  45.     time.sleep(0.5)
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement