Python run on Raspberry Pi OS to check memory and disk info using psutil.
psutil
(python system and process utilities) is a cross-platform library for
retrieving information on running processes and system utilization (CPU,
memory, disks, network, sensors) in Python. It is useful mainly for system
monitoring, profiling, limiting process resources and the management of
running processes.
It's a simple Python exercise run on Raspberry Pi 5/8G running
Raspberry Pi OS 64-bit (bookworm), to check memory and disk info using
psutil.
psutil_info.py
import psutil #https://psutil.readthedocs.io/en/latest/index.html
memory = psutil.virtual_memory()
memory_available = round(memory.available/(1024*1024))
memory_total = round(memory.total/(1024*1024))
# Calculate disk information
disk = psutil.disk_usage('/')
disk_used = round(disk.used/(1024*1024*1024))
disk_total = round(disk.total/(1024*1024*1024))
print(psutil.__name__, psutil.__version__)
print()
print("Memory:\t",
str(memory_available), "MB available /", str(memory_total), "MB total (" + str(memory.percent) + "%)")
print("Disk:\t",
str(disk_used), "GB used /", str(disk_total), "GB total (" + str(disk.percent) + "% usage)")
Output:psutil 5.9.4
Memory: 6406 MB available / 8050 MB total (20.4%)
Disk: 6 GB used / 117 GB total (5.0% usage)
Comments
Post a Comment