system_info
system_info
system_info gives Crystal applications a single, typed API for inspecting the host system. It reports operating-system and architecture details, CPU and memory capacity, filesystem usage and mounted volumes, network interfaces, connected displays, locale settings, and conventional application directories.
The platform-specific work is handled internally, so application code uses the same API on macOS, Linux, and Windows. Results are returned as immutable Crystal records that serialize to JSON.
Use it for diagnostics, status pages, installers, and monitoring.
Supported platforms:
- macOS
- Linux
- Windows
Installation
dependencies:
system_info:
github: naqvis/system_info
Then run shards install.
Quick start
require "system_info"
puts SystemInfo.os
puts SystemInfo.hostname
puts SystemInfo.architecture
puts SystemInfo.cpu
memory = SystemInfo.memory
puts "Memory: #{memory.used.humanize_bytes(unit_separator: " ")} / #{memory.total.humanize_bytes(unit_separator: " ")}"
disk = SystemInfo.filesystem("/")
puts "Disk: #{disk.available.humanize_bytes(unit_separator: " ")} available"
Values are returned as immutable records. Memory and storage sizes remain exact Int64 byte counts, so you can format or compute them as you like — the example uses the standard library's Number#humanize_bytes method for display. CPU frequency is reported in GHz when the operating system provides it.
Host snapshot
snapshot collects the commonly used host facts in one value:
snapshot = SystemInfo.snapshot
snapshot.os
snapshot.architecture
snapshot.hostname
snapshot.cpu
snapshot.memory
snapshot.locale
snapshot.directories
Storage volumes, network interfaces, and displays are excluded because enumerating them may be slower or require additional system services. Request them when needed.
Storage
SystemInfo.filesystem("/path/to/file")
SystemInfo.volumes.each do |volume|
puts "#{volume.name}: #{volume.mount_point}"
puts " #{volume.available} / #{volume.total} bytes available"
puts " removable: #{volume.removable?}"
end
filesystem(path) reports the filesystem containing the path. volumes returns mounted local volumes sorted by mount point. Some operating systems cannot identify removable media perfectly; unknown volumes report false.
Network interfaces
SystemInfo.network_interfaces.each do |interface|
puts "#{interface.name}: #{interface.address} #{interface.mac_address}"
end
Only interfaces with a configured IP address are returned. An interface may have an empty MAC address when the platform does not expose one.
Displays
SystemInfo.displays.each do |display|
puts "#{display.width}x#{display.height} @#{display.scale_factor}x"
puts "primary" if display.primary?
end
Display dimensions are logical pixels where the platform makes that distinction.
Locale and directories
locale = SystemInfo.locale
puts locale.name
puts locale.language
directories = SystemInfo.directories
puts directories.data
puts directories.config
puts directories.cache
puts directories.system_data
Directory paths are conventional locations for the current platform. The shard does not create them.
Example
crystal run examples/overview.cr
Development
crystal spec
License
MIT
Contributors
- Ali Naqvi — creator and maintainer
system_info
- 0
- 0
- 0
- 0
- 0
- about 6 hours ago
- August 23, 2026
MIT License
Sun, 23 Aug 2026 12:42:33 GMT