kwutil.util_hardware module¶
Helpers to get information about the available hardware. Request info about things like cpus, gpus, memory, and disk.
Backed by external modules:
cpuinfo.
psutil.and various linux cli calls via
ubelt.cmd().
- kwutil.util_hardware.get_mem_info(with_units=False)[source]¶
Memory info is returned in bytes.
Todo
[ ] Should we use pint to give these numbers units?
References
https://psutil.readthedocs.io/en/latest/#psutil.virtual_memory
Example
>>> # xdoctest: +REQUIRES(module:psutil) >>> from kwutil import util_hardware >>> import ubelt as ub >>> mem_info = util_hardware.get_mem_info(with_units=1) >>> print(f'mem_info = {ub.urepr(mem_info, nl=1)}')
total = mem_info[‘used’] tmp = (
# mem_info[‘cached’] + # mem_info[‘buffers’] + # mem_info[‘inactive’] + mem_info[‘slab’])
green = total - tmp print(f’green={green}’) percent = ((green / mem_info[‘total’]) * 100).m print(f’percent={percent}’)
- kwutil.util_hardware.disk_info_of_path(path)[source]¶
Get disk info wrt where a file lives
WIP - needs more work
CommandLine
xdoctest -m kwutil.util_hardware disk_info_of_path
- Returns:
dict - dictionary of information
Example
>>> from kwutil.util_hardware import * # NOQA >>> path = '.' >>> x = disk_info_of_path(path) >>> import ubelt as ub >>> print(ub.urepr(x))
Todo
[ ] Handle btrfs
[ ] Handle whatever AWS uses
[ ] Use udisksctl or udevadm
References
https://askubuntu.com/questions/609708/how-to-find-hard-drive-brand-name-or-model https://stackoverflow.com/questions/38615464/how-to-get-device-name-on-which-a-file-is-located-from-its-path-in-c
- kwutil.util_hardware._zfs_status(pool, verbose=0)[source]¶
Semi-parsable zfs status output. This is a proof-of-concept and needs some work to handle the nested pool structure.
- class kwutil.util_hardware.CPUs[source]¶
Bases:
_HardwareComponentStorage container for info about system CPUs.
- class kwutil.util_hardware.Memory[source]¶
Bases:
_HardwareComponentStorage container for info about system RAM.
- class kwutil.util_hardware.GPUs[source]¶
Bases:
_HardwareComponentStorage container for info about system GPUS.
- class kwutil.util_hardware.Motherboard[source]¶
Bases:
_HardwareComponentStorage container for info about system motherboard.
References
https://askubuntu.com/questions/179958/how-do-i-find-out-my-motherboard-model
- class kwutil.util_hardware.Disks[source]¶
Bases:
_HardwareComponentStorage container for info about system storage disks.
Todo
Find all mounted filesystems that correspond with physical disks via
cat /proc/mountsormount -lReferences
- class kwutil.util_hardware.Networking[source]¶
Bases:
_HardwareComponentStorage container for info about system networking devices.
- class kwutil.util_hardware.Peripherals[source]¶
Bases:
_HardwareComponentStorage container for info about system peripherals.
- class kwutil.util_hardware.Hardware[source]¶
Bases:
objectTODO: class level namespace
References
https://pypi.org/project/hardware/
Example
>>> # xdoctest: +SKIP >>> import kwutil >>> kwutil.Hardware.report()