Monitoring your devices in Python
Profile and Monitor System Resources in Python using psutil and GPUtil
--
Why is monitoring system resources important?
If you cannot measure it, you cannot improve it- Lord Kelvin
Monitoring helps to regularly evaluate the performance of the critical system resources like
- CPU
- Memory -RAM, Swap space, and Hard disk space
- Network usage
- GPU usage
Monitoring is critical in identifying the process that is utilizing the most resources and why. It helps to understand if the current system's resources are sufficient for running or a rogue process is consuming too many resources.
Having a limiting threshold on the systems resources will prevent further escalation of the issues and identify an appropriate root cause analysis to fix the issue.
Here we will explore
psutil(process and system utilities) library in Python is a cross-platform library for retrieving information on running processes and system utilization for resources like CPU, memory, disks, network, sensors.
psutil currently supports the following platforms:
- Linux
- Windows
- macOS
- FreeBSD, OpenBSD, NetBSD
- Sun Solaris
- AIX
GPUtil is a Python module for getting the GPU status from NVIDIA GPUs using nvidia-smi.
System profile
Profile your system to know the system name, OS version, if the system is a 64-bit architecture or 32-bit architecture, number of physical and virtual cores, and the max and min frequency of the CPU
Platform library retrieves platform-identifying data like device name, OS version, OS release version, node, processor, etc.
import psutil
import platform
uname = platform.uname()
print(f"System: {uname.system}") #Windows or Linux
print(f"Node Name: {uname.node}") # System name
print(f"Release: {uname.release}") # OS release version like 10(Windows) or…