Device Module
The Device module includes powerful tools for managing and retrieving detailed information about your system’s disks and CPU, enhancing productivity and ensuring efficient system management in applications.
Features
Boot Time: Provides the system’s boot time.
Current Disk Filesystem Name: Returns the name of the current disk filesystem.
Disk Info: Displays detailed information about the disks.
Disk I/O Counters: Returns disk I/O counters.
Disk Partitions: Retrieves disk partitions.
Boot Drive Name: Returns the name of the boot drive.
Filter by Device: Filters disk partitions based on the device.
Filter by Filesystem Type: Filters disk partitions based on filesystem type.
Filter by Mount Point: Filters disk partitions based on the mount point.
Filter by Options: Filters disk partitions based on options.
Storage Metrics: Provides storage metrics for a specific mount point.
CPU Usage Percentage: Returns the CPU usage percentage.
CPU Usage Times: Provides CPU usage times.
CPU Count: Returns the number of CPUs (logical cores) available in the system.
Disks
The Disks section of the Device module provides powerful tools for managing and retrieving detailed information about disk partitions, boot drive names, filesystem types, and storage metrics. It enhances productivity by simplifying disk management and ensuring efficient retrieval of disk-related information.
# Disks
—
## Overview
The Disks module provides a comprehensive set of functionalities for managing and retrieving various disk-related information and metrics. This module is divided into two main parts: Disk Information and Disk Usage. It leverages the psutil library to gather details efficiently and offers filtering capabilities to narrow down the information based on specific criteria.
### Disk Information
The Disk Information part of the module provides functionalities for retrieving various disk-related information, such as disk partitions, boot drive names, and filesystem types. It offers filtering capabilities to narrow down the information based on specific criteria.
#### Functions:
current_disk_filesystem_name - Returns: str - The filesystem type of the current disk.
boot_time - Returns: str - The boot time in the format day/month/year hour:minute:second.
get_disk_partitions - Returns: list - A list of dictionaries, each containing the attributes of a mounted disk partition.
get_boot_drive_name - Returns: str - The name of the boot drive on macOS. If the function is called on a non-macOS platform, it returns “NOT IMPLEMENTED”.
get_disk_partition_filteredby_device - Returns: list - A list of dictionaries, each containing the attributes of a disk partition that matches the specified device filter.
get_disk_partition_filteredby_fstype - Returns: list - A list of dictionaries, each containing the attributes of a disk partition that matches the specified filesystem type filter.
get_disk_partition_filteredby_mountpoint - Returns: list - A list of dictionaries, each containing the attributes of a disk partition that matches the specified mount point filter.
get_disk_partition_filteredby_opts - Returns: list - A list of dictionaries, each containing the attributes of a disk partition that matches the specified options filter.
### Disk Usage
The Disk Usage part of the module provides functionalities for retrieving various disk usage metrics, such as total, free, and used storage, as well as the percentage of free and used storage. It also includes functions for retrieving comprehensive information about the system’s disk partitions and disk I/O counters.
#### Functions:
storage_metrics - Returns: dict - A dictionary containing storage metrics for a specific mount point.
disk_info - Returns: dict - A dictionary where each key is an index and each value is a tuple containing the attributes of a disk partition.
disk_io_counters - Returns: dict - A dictionary where each key is a disk name and each value is an object containing disk I/O statistics.
The Disks module is designed to provide essential disk-related information and usage metrics for system monitoring and management tasks. By utilizing the psutil library, it ensures accurate and efficient retrieval of disk metrics and attributes.
- filesystem.device.disks.boot_time()[source]
# disks.boot_time()
—
### Overview
Retrieves the system’s boot time. This function uses the psutil.boot_time() method to get the boot time as a timestamp and then converts it to a human-readable format.
### Parameters: - None
### Returns: - str: The boot time in the format day/month/year hour:minute:second.
### Raises: - None
### Examples: - Retrieves the system’s boot time.
`python boot_time_str = boot_time() print(boot_time_str) `
- filesystem.device.disks.current_disk_filesystem_name()[source]
# disks.current_disk_filesystem_name()
—
### Overview
Retrieves the filesystem type of the current disk. This function checks the disk partitions and returns the filesystem type of the partition mounted at ‘C:/’ (for Windows) or ‘/’ (for Unix-like systems).
### Parameters: - None
### Returns: - str: The filesystem type of the current disk.
### Raises: - None
### Examples: - Retrieves the filesystem type of the current disk.
`python filesystem_type = current_disk_filesystem_name() print(filesystem_type) `
- filesystem.device.disks.disk_info()[source]
# disks.disk_info()
—
### Overview
Retrieves comprehensive information about the system’s disk partitions, including devices, filesystem types, mount points, options, and storage metrics. This function consolidates data from multiple helper functions to provide detailed disk information.
### Parameters: - None
### Returns: - dict: A dictionary where each key is an index and each value is a tuple containing the attributes of a disk partition: - Mount point - Device - Filesystem type - Options - Total storage - Used storage - Free storage - Percentage of used storage - Percentage of free storage
### Raises: - None
### Examples: - Retrieves detailed information about the system’s disk partitions.
`python disk_information = disk_info() print(disk_information) `
- filesystem.device.disks.disk_io_counters()[source]
# disks.disk_io_counters()
—
### Overview
Retrieves disk I/O statistics for each disk in the system. This function utilizes the psutil.disk_io_counters method to gather I/O counters for each disk, including the number of read and write operations, the number of bytes read and written, and the time spent reading and writing.
### Parameters: - None
### Returns: - dict: A dictionary where each key is a disk name and each value is an object containing disk I/O statistics.
### Raises: - None
### Examples: - Retrieves disk I/O statistics for all disks.
`python io_counters = disk_io_counters() print(io_counters) `
- filesystem.device.disks.drive_name = '/home/docs/checkouts/readthedocs.org/user_builds/filesystempro'
This variable stores the name of the boot drive on the current platform.
On macOS, the function uses a subprocess call to the Foundation framework to obtain the display name of the boot drive.
On Windows, it returns the name of the boot drive.
On Linux, it returns the name of the boot drive.
If the function is called on an unsupported platform, it returns “Unsupported platform: _platform_name_”.
- filesystem.device.disks.get_boot_drive_name()[source]
# disks.get_boot_drive_name()
—
### Overview
Retrieves the name of the boot drive.
### Parameters: - None
### Returns: - str: The name of the boot drive.
### Raises: - Exception: If an error occurs during the subprocess call, it returns “Unsupported platform: _platform_name_”.
### Examples: - Retrieves the name of the boot drive on macOS.
`python boot_drive_name = get_boot_drive_name() print(boot_drive_name) `
- filesystem.device.disks.get_disk_partition_filteredby_device(filter)[source]
# disks.get_disk_partition_filteredby_device(filter)
—
### Overview
Filters and retrieves disk partitions based on the specified device. This function compares the device attribute of each partition with the provided filter and returns a list of matching partitions.
### Parameters: - filter (str): The device name to filter the disk partitions by.
### Returns: - list: A list of dictionaries, each containing the attributes of a disk partition that matches the specified device filter.
### Raises: - None
### Examples: - Filters disk partitions by the device name sda1.
`python partitions = get_disk_partition_filteredby_device('sda1') print(partitions) `
- filesystem.device.disks.get_disk_partition_filteredby_fstype(filter)[source]
# disks.get_disk_partition_filteredby_fstype(filter)
—
### Overview
Filters and retrieves disk partitions based on the specified filesystem type. This function compares the filesystem type attribute of each partition with the provided filter and returns a list of matching partitions.
### Parameters: - filter (str): The filesystem type to filter the disk partitions by.
### Returns: - list: A list of dictionaries, each containing the attributes of a disk partition that matches the specified filesystem type filter.
### Raises: - None
### Examples: - Filters disk partitions by the filesystem type ext4.
`python partitions = get_disk_partition_filteredby_fstype('ext4') print(partitions) `
- filesystem.device.disks.get_disk_partition_filteredby_mountpoint(filter)[source]
# disks.get_disk_partition_filteredby_mountpoint(filter)
—
### Overview
Filters and retrieves disk partitions based on the specified mount point. This function compares the mount point attribute of each partition with the provided filter and returns a list of matching partitions.
### Parameters: - filter (str): The mount point to filter the disk partitions by.
### Returns: - list: A list of dictionaries, each containing the attributes of a disk partition that matches the specified mount point filter.
### Raises: - None
### Examples: - Filters disk partitions by the mount point /mnt/data.
`python partitions = get_disk_partition_filteredby_mountpoint('/mnt/data') print(partitions) `
- filesystem.device.disks.get_disk_partition_filteredby_opts(filter)[source]
# disks.get_disk_partition_filteredby_opts(filter)
—
### Overview
Filters and retrieves disk partitions based on the specified options. This function compares the options attribute of each partition with the provided filter and returns a list of matching partitions.
### Parameters: - filter (str): The options to filter the disk partitions by.
### Returns: - list: A list of dictionaries, each containing the attributes of a disk partition that matches the specified options filter.
### Raises: - None
### Examples: - Filters disk partitions by the options rw.
`python partitions = get_disk_partition_filteredby_opts('rw') print(partitions) `
- filesystem.device.disks.get_disk_partitions()[source]
# disks.get_disk_partitions()
—
### Overview
Retrieves a list of all mounted disk partitions and their attributes. This function converts the partition details into dictionary format for easier access and manipulation.
### Parameters: - None
### Returns: - list: A list of dictionaries, each containing the attributes of a mounted disk partition.
### Raises: - None
### Examples: - Retrieves the list of all mounted disk partitions.
`python partitions = get_disk_partitions() print(partitions) `
- filesystem.device.disks.storage_metrics(mountpoint)[source]
# disk.storage_metrics(mountpoint)
—
### Overview
Returns storage metrics for a specific mount point, including total, free, and used storage, as well as the percentage of free and used storage.
### Parameters: - mountpoint (str): The path of the mount point to get storage metrics for.
### Returns: - dict: A dictionary containing storage metrics: - 0: Total storage. - 1: Free storage. - 2: Used storage. - 3: Percentage of free storage. - 4: Percentage of used storage.
### Raises: - None
### Examples: - Retrieves storage metrics for the root mount point.
`python storage_metrics('/') `
CPU
The CPU section of the Device module offers essential metrics and functionalities for monitoring CPU performance, including CPU usage percentage, CPU times, and the number of CPU cores. It empowers developers to efficiently manage and optimize CPU usage within their applications.
# CPU
—
## Overview
The CPU module provides functionalities for retrieving CPU-related information such as CPU usage percentage, CPU times, and the number of CPU cores. It leverages the psutil library to gather these details efficiently.
The CPU module is designed to provide essential CPU-related information for system monitoring and management tasks. By utilizing the psutil library, it ensures accurate and efficient retrieval of CPU metrics.
- filesystem.device.cpu.cpu_count()[source]
# cpu.cpu_count()
—
### Overview
Retrieves the number of CPU cores in the system. This function uses the psutil.cpu_count() method to get the total number of logical CPU cores available.
### Parameters: - None
### Returns: - int: The number of logical CPU cores.
### Raises: - None
### Examples: - Retrieves the number of logical CPU cores in the system.
`python num_cores = cpu_count() print(num_cores) `
- filesystem.device.cpu.cpu_percent()[source]
# cpu.cpu_percent()
—
### Overview
Retrieves the system’s CPU usage percentage. This function uses the psutil.cpu_percent() method to get the current CPU usage as a percentage.
### Parameters: - None
### Returns: - float: The CPU usage percentage.
### Raises: - None
### Examples: - Retrieves the system’s current CPU usage percentage.
`python cpu_usage = cpu_percent() print(cpu_usage) `
- filesystem.device.cpu.cpu_times()[source]
# cpu.cpu_times()
—
### Overview
Retrieves CPU times for the system. This function uses the psutil.cpu_times() method to get the amount of time the CPU has spent in various states such as user, system, idle, etc.
### Parameters: - None
### Returns: - psutil._pslinux.scputimes: An object containing the CPU times for the various states.
### Raises: - None
### Examples: - Retrieves the system’s CPU times.
`python cpu_times_info = cpu_times() print(cpu_times_info) `