psutil
modulepsutil
(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
disk_usage
methodThe sensors_fans
method returns the disk usage statistics about the partition of the given path as a named tuple. The named tuple consists of the following attributes:
total
: This represents the total amount of memory.used
: This represents used memory.free
: This represents free memory.percent
: This represents the percentage usage of the memory.All the above attributes are reported in bytes.
psutil.disk_usage(path)
path
: This is the file path.The method has no parameters.
import psutil, osprint("The usage statistics of " + os.getcwd() + " is:")print(psutil.disk_usage(os.getcwd()))
psutil
and os
modules.psutil.disk_usage()
method to retrieve the usage statistics of the current working directory, and pass the current working directory as the file path. We use the os.getcwd()
method to obtain the current working directory.