psutil
module?The psutil
(Python system and process utilities) is a Python package that retrieves information on ongoing processes and system usage (CPU, memory, storage, network, and sensors). It is mostly used for system monitoring, profiling, restricting process resources, and process management.
The module can be installed via pip
, as follows:
pip install psutil
cpu_stats
methodThe cpu_stats
method is used to return the following CPU statistics attributes as a named tuple:
ctx_switches
: This represents the number of context switches since the boot.interrupts
: This represents the number of interrupts since boot.soft_interrupts
: This represents the number of software interrupts since boot.syscalls
: This represents the number of system calls since boot.psutil.cpu_stats()
The method has no parameters.
import psutilprint("The current stats of the CPU are as follows:")print(psutil.cpu_stats())
psutil
.cpu_stats()
method.