hardware module provides cross-platform functions to query hardware information including CPU, GPU, memory, disk, and battery status.
Platform support varies by function. Most functions support Linux, macOS, and BSD variants. Functions return “unknown” when information is unavailable.
CPU information
Functions for querying CPU details.hardware::cpu::name()
hardware::cpu::name()
Get the CPU model name.Automatically strips marketing terms like (TM), (R), “Processor”, “Dual-Core”, etc.Returns: CPU model name or “unknown”Platforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
hardware::cpu::core_count::physical()
hardware::cpu::core_count::physical()
Get the number of physical CPU cores.Returns: Number of physical coresPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
hardware::cpu::core_count::logical()
hardware::cpu::core_count::logical()
Get the number of logical CPU cores (threads).Returns: Number of logical cores (including hyperthreading)Platforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
hardware::cpu::core_count::total()
hardware::cpu::core_count::total()
Alias for Returns: Total thread count
hardware::cpu::core_count::logical().hardware::cpu::thread_count()
hardware::cpu::thread_count()
Alias for Returns: Thread count
hardware::cpu::core_count::logical().hardware::cpu::frequencyMHz()
hardware::cpu::frequencyMHz()
Get the current CPU frequency in MHz.Tries multiple sources: scaling_cur_freq, bios_limit, scaling_max_freq, cpuinfo_max_freq.Returns: CPU frequency in MHz or “unknown”Platforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
hardware::cpu::temp()
hardware::cpu::temp()
Get the CPU temperature in Celsius.Returns: Temperature in Celsius with one decimal place, or “unknown”Platforms: Linux, FreeBSD, DragonFly, OpenBSD, NetBSD
macOS requires third-party tools like
osx-cpu-temp.GPU information
Functions for querying GPU details.hardware::gpu()
hardware::gpu()
Get the GPU model name.Tries multiple detection methods: nvidia-smi, lspci, glxinfo (Linux); system_profiler (macOS); pciconf (FreeBSD).Returns: GPU model name or “unknown”Platforms: Linux, macOS, FreeBSD, DragonFly
hardware::gpu::vramMB()
hardware::gpu::vramMB()
Get GPU VRAM in megabytes.Returns: VRAM in MB or “unknown”Platforms: Linux (nvidia-smi, lspci), macOS
Memory (RAM) information
Functions for querying system memory.hardware::ram::totalSpaceMB()
hardware::ram::totalSpaceMB()
Get total RAM in megabytes.Returns: Total RAM in MBPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
hardware::ram::freeSpaceMB()
hardware::ram::freeSpaceMB()
Get free RAM in megabytes.Returns: Available RAM in MBPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
hardware::ram::usedSpaceMB()
hardware::ram::usedSpaceMB()
Get used RAM in megabytes.Returns: Used RAM in MBPlatforms: Linux, macOS, FreeBSD, OpenBSD, NetBSD
Disk information
Functions for querying disk space.hardware::disk::totalSpaceGB([path])
hardware::disk::totalSpaceGB([path])
Get total disk space in gigabytes.Parameters:
path- Path to check (default: /)
hardware::disk::freeSpaceGB([path])
hardware::disk::freeSpaceGB([path])
Get free disk space in gigabytes.Parameters:
path- Path to check (default: /)
hardware::disk::usedSpaceGB([path])
hardware::disk::usedSpaceGB([path])
Get used disk space in gigabytes.Parameters:
path- Path to check (default: /)
hardware::disk::usagePercent([path])
hardware::disk::usagePercent([path])
Get disk usage percentage.Parameters:
path- Path to check (default: /)
Battery information
Functions for querying battery status (laptops).hardware::battery::percent()
hardware::battery::percent()
Get battery charge percentage.Returns: Battery percentage (0-100) or “unknown”Platforms: Linux, macOS
hardware::battery::status()
hardware::battery::status()
Get battery status.Returns: Battery status or “unknown”Platforms: Linux, macOS
hardware::battery::is_charging()
hardware::battery::is_charging()
Check if battery is currently charging.Returns: Exit code 0 if chargingPlatforms: Linux, macOS