Cross-platform system information: OS, CPU, memory, disk, host, timezone, power, process, env, load, and locale for Alya
- π₯οΈ OS Identification: Canonical platform id, human-readable version, kernel release, distro id/version (Linux), CPU arch, admin/root detection
- β‘ CPU Reporting: Logical + physical core counts, base frequency, vendor and model strings per OS
- π§ Memory Reporting: Total/available RAM plus swap/pagefile, with MB and usage-percent helpers
- πΎ Disk Usage: Total/free bytes per path, filesystem type, and full volume enumeration
- π Host Identity: Hostname and username via native API with env fallback
- π Timezone & Uptime: System timezone name + UTC offset, seconds-since-boot and boot timestamp
- π Power & Battery: Charge percent and AC-line status (unknown-safe on desktops)
- βοΈ Process & Environment: Current pid/exe path, full environment map access
- π Load Average: 1/5/15-minute load on POSIX (
-1.0on Windows) - π Locale Detection: Native locale API with
LANGUAGE/LC_*/LANGfallback, BCP-47 normalization, fallback chains - π§© Modular Architecture: Layered multi-module design with a clean public facade (
src/lib.alya) and canonical models (src/types.alya) - π Public/Private Visibility (
pub): Fine-grained export control keeping internals encapsulated - π§ͺ Enterprise Test & Benchmark Suite: Real-hardware assertions (
std/test) and micro-benchmarking
sysinfo/
βββ .alyalint # Linter configuration (rules, exclusions, severity overrides)
βββ .editorconfig # Uniform formatting rules across IDEs and editors
βββ .gitignore # Ecosystem standard ignore filters
βββ .vscode/ # VS Code workspace settings, DAP launch configurations & tasks
βββ alya.toml # Package manifest with dependencies and optional [build]
βββ c/ # Native C sources for zero-dependency FFI packages
β βββ sysinfo.h # Shared native declarations
β βββ sysinfo.c # Common fallback engine
β βββ win32_locale.c # Windows locale (GetUserDefaultLocaleName)
β βββ win32_sysinfo.c # Windows OS/CPU/RAM/disk/TZ/uptime
β βββ cocoa_locale.c # macOS locale (CFLocale)
β βββ cocoa_sysinfo.c # macOS sysctl/VM/statvfs/timezone
β βββ linux_locale.c # Linux locale (setlocale/env)
β βββ linux_sysinfo.c # Linux /proc/statvfs/timezone
βββ src/
β βββ lib.alya # Public API facade (system_info, summary, locale)
β βββ types.alya # Data models (OsInfo, CpuInfo, MemInfo, DiskUsage, ...)
β βββ ffi.alya # Native extern "C" declarations
β βββ locale.alya # Locale detection, normalization, fallback chains
β βββ os_info.alya # OS name/version/arch/kernel/distro/elevation
β βββ cpu.alya # CPU cores (logical+physical)/freq/vendor/model
β βββ mem.alya # Memory + swap totals
β βββ disk.alya # Disk usage per path + volume enumeration
β βββ host.alya # Hostname/username
β βββ timezone.alya # Timezone name/offset
β βββ power.alya # Battery percent / AC status
β βββ proc.alya # pid + executable path
β βββ env_info.alya # Full environment map access
β βββ load.alya # Load averages (POSIX)
β βββ uptime.alya # Uptime counters + boot timestamp
β βββ core/ # Subdirectory module hierarchy
β βββ formatter.alya # format_bytes/duration/offsets, mem/disk/power/cpu, summary + details
βββ examples/
β βββ demo.alya # Runnable walkthrough of all package capabilities
βββ tests/
β βββ test_basic.alya # Automated test suite (real-hardware assertions)
βββ benches/
βββ bench_basic.alya # Micro-benchmarks measuring performance and throughput
Note
Visibility & Modularity: Symbols annotated with pub (pub function, pub struct, pub enum, pub interface) are exported to external consumers and re-exporting modules. Symbols without pub remain strictly internal to their declaring module, preventing symbol collisions and implementation leakage.
Add sysinfo to the [dependencies] section in your alya.toml:
[dependencies]
sysinfo = { git = "https://github.com/alya-lang/sysinfo", branch = "main" }Or install it directly using the Alya package CLI:
alya add sysinfo --git https://github.com/alya-lang/sysinfo --branch main
alya install| Feature | Default | Description |
|---|---|---|
timezone |
β | Timezone database and zone info (tz_info, tz_iana, ...). |
power |
β | Power/battery reporting (battery, power_info, ...). |
locale |
β | System locale detection (system_lang, locale_info, ...). |
net |
β | Network interfaces and rates (net_interfaces, net_rates, ...). |
system_info(), summary(), and details() need all four (they aggregate every domain). OS/CPU/memory/disk/host/process/env/load/uptime always work.
# Full build (default)
alya install
alya test
# Slim build (core domains only)
alya install --no-default-features
alya test --no-default-featuresimport "sysinfo" as pkg
function main()
# 1. Full snapshot in one call
let info = pkg::system_info()
say f"OS: {info.os.version}"
say f"CPU: {info.cpu.model} x{info.cpu.cores}"
say f"Memory: {pkg::format_mem(info.mem)}"
say f"Locale: {info.locale}"
# 2. One-line summary
say pkg::summary()
end
main()
| Symbol | Visibility | Description |
|---|---|---|
system_info() |
pub function |
Collects a full SystemInfo snapshot (OS, CPU, RAM, disk, host, TZ, uptime, locale). |
summary() |
pub function |
Returns a one-line human-readable system summary. |
os_name() |
pub function |
Canonical OS id ("windows", "linux", "macos"). |
os_version() |
pub function |
Human-readable OS version with OS-id fallback. |
os_arch() |
pub function |
Canonical CPU arch id ("x64", "x86", "arm64"). |
os_info() |
pub function |
Collects an OsInfo record. |
kernel() |
pub function |
Kernel release ("NT 10.0.26200", "24.6.0"). |
distro_id() |
pub function |
Distribution/edition id ("ubuntu", Windows EditionID, "" when unavailable). |
distro_version() |
pub function |
Distribution version ("24.04", Windows DisplayVersion, "" when unavailable). |
elevated() |
pub function |
1 when admin/root, 0 when not, -1 on detection failure. |
cpu_cores() |
pub function |
Logical processor count (>= 1). |
cpu_physical() |
pub function |
Physical core count (falls back to logical). |
cpu_freq_mhz() |
pub function |
Base frequency in MHz (-1 when unavailable). |
cpu_vendor_name() |
pub function |
CPU vendor ("GenuineIntel", "AuthenticAMD", "Apple"). |
cpu_model() |
pub function |
Human-readable CPU model ("" when unavailable). |
cpu_info() |
pub function |
Collects a CpuInfo record. |
mem_total_bytes() |
pub function |
Total physical RAM in bytes (-1 when unavailable). |
mem_avail_bytes() |
pub function |
Available physical RAM in bytes (-1 when unavailable). |
mem_info() |
pub function |
Collects a MemInfo record. |
swap_total() |
pub function |
Total swap/pagefile in bytes (-1 when unavailable). |
disk_total_bytes(path) |
pub function |
Filesystem total bytes for path (-1 when unavailable). |
disk_free_bytes(path) |
pub function |
Filesystem free bytes for path (-1 when unavailable). |
disk_fs(path) |
pub function |
Filesystem type ("NTFS", "ext4", "" when unavailable). |
volumes() |
pub function |
Usage records (DiskUsage) for every mounted volume. |
disk_usage(path) |
pub function |
Collects a DiskUsage record (defaults to disk_default_path()). |
host_name() |
pub function |
Machine hostname via native API with env fallback. |
host_user() |
pub function |
Current user name (native lookup first, then env). |
host_info() |
pub function |
Collects a HostInfo record. |
tz_name() |
pub function |
System timezone name with TZ fallback. |
utc_offset_min() |
pub function |
UTC offset in minutes (UTC+3 -> 180). |
tz_info() |
pub function |
Collects a TzInfo record. |
uptime_sec() |
pub function |
Seconds since boot (-1 when unavailable). |
boot_time() |
pub function |
Unix timestamp of the last boot (-1 when unavailable). |
battery() |
pub function |
Battery charge 0-100 (-1 when no battery/unknown). |
power_info() |
pub function |
Collects a PowerInfo record. |
exe_path() |
pub function |
Current executable path ("" when unavailable). |
proc_info() |
pub function |
Collects a ProcInfo record (pid, exe). |
env_map() |
pub function |
Whole environment as a name -> value map. |
env_len() |
pub function |
Number of environment variables. |
env_val(key, default) |
pub function |
Environment variable value or fallback. |
load() |
pub function |
[1min, 5min, 15min] load averages (-1.0 when unavailable). |
details() |
pub function |
Detailed multi-line system report. |
system_lang(default) |
pub function |
Best system locale tag ("tr-TR"), "en" fallback. |
system_langs() |
pub function |
Locale fallback chain (["tr-TR", "tr", "en"]). |
normalize_locale(raw) |
pub function |
Normalizes "tr_TR.UTF-8" to "tr-TR". |
locale_info() |
pub function |
Collects a LocaleInfo record for the system locale. |
format_bytes(n) |
pub function |
Formats bytes as "15 GB", "512 MB", "unknown" when negative. |
format_duration(sec) |
pub function |
Formats seconds as "3d 4h", "5h 12m", "45s". |
format_utc_offset(min) |
pub function |
Formats minutes as "UTC+3", "UTC". |
format_mem(info) |
pub function |
One-line RAM overview ("RAM 13289/16127 MB (82%)"). |
format_disk(usage) |
pub function |
One-line disk overview ("C:/ 188/199 GB (94%)"). |
format_system_summary(info) |
pub function |
Full multi-field snapshot line. |
OsInfo |
pub struct |
OS model (name, version, arch, kernel, distro_id, distro_version). |
CpuInfo |
pub struct |
CPU model (arch, cores, physical_cores, freq_mhz, model, vendor). |
MemInfo |
pub struct |
Memory model (total_bytes, avail_bytes, swap_total_bytes, swap_avail_bytes) + total_mb(), avail_mb(), used_percent(), is_known(), swap_mb(), swap_used_percent(). |
DiskUsage |
pub struct |
Disk model (path, fstype, total_bytes, free_bytes) + used_bytes(), used_percent(), is_known(). |
HostInfo |
pub struct |
Host model (hostname, username). |
TzInfo |
pub struct |
Timezone model (name, offset_min). |
LocaleInfo |
pub struct |
Locale model (bcp47, lang, region). |
SystemInfo |
pub struct |
Aggregated snapshot (os, cpu, mem, disk, host, tz, power, proc, uptime_sec, locale). |
PowerInfo |
pub struct |
Power model (battery_percent, on_ac) + has_battery(), is_on_ac(). |
ProcInfo |
pub struct |
Process model (pid, exe). |
Tip
Internal Helpers & Documentation: Public symbols are documented with ## Markdown docstrings, enabling automatic API documentation generation via alya doc. Private helpers remain encapsulated without pub.
[!NOTE]
FFI string ownership: Native str results are zero-copy views into C static buffers. Every stored or returned FFI string is pinned to a heap copy at the module boundary via str_owned() (src/core/strutil.alya), so snapshots stay valid across further FFI calls.
| Capability | Windows | macOS | Linux |
|---|---|---|---|
| OS version | RtlGetVersion (ntdll) |
kern.osproductversion |
/etc/os-release |
| Kernel | NT version | uname |
uname |
| Distro id/version | β | β | /etc/os-release |
| CPU cores (logical/physical) | GetSystemInfo / GetLogicalProcessorInformation |
hw.logicalcpu / hw.physicalcpu |
/proc/cpuinfo |
| CPU frequency | Registry ~MHz |
hw.cpufrequency |
/proc/cpuinfo |
| CPU vendor | CPUID |
machdep.cpu.vendor |
/proc/cpuinfo |
| RAM | GlobalMemoryStatusEx |
hw.memsize + host_statistics64 |
/proc/meminfo |
| Swap | Pagefile counters | vm.swapusage |
/proc/meminfo |
| Disk usage | GetDiskFreeSpaceEx |
statvfs |
statvfs |
| Filesystem type | GetVolumeInformation |
statfs |
statfs magic |
| Volume list | Drive strings | getmntinfo |
/proc/mounts |
| Hostname | GetComputerName |
gethostname |
gethostname |
| Timezone | GetDynamicTimeZoneInformation |
CFTimeZone |
/etc/localtime + tm_gmtoff |
| Uptime / boot | GetTickCount64 |
KERN_BOOTTIME |
/proc/uptime + btime |
| Battery | GetSystemPowerStatus |
IOKit power sources | /sys/class/power_supply |
| Executable path | GetModuleFileName |
_NSGetExecutablePath |
/proc/self/exe |
| Environment map | GetEnvironmentStrings |
environ |
environ |
| Load average | β (-1.0) |
getloadavg |
getloadavg |
| Elevation | Administrators SID | geteuid |
geteuid |
| Locale | GetUserDefaultLocaleName |
CFLocale |
setlocale + env |
Run the automated test suite using alya test:
alya testGenerate static API documentation:
alya doc . -o docs --markdownRun the benchmark suite:
alya run benches/bench_basic.alyaRun the example demo:
alya run examples/demo.alyaCheck code formatting:
alya fmt . --checkRun static code linter:
alya lint . --checkThis package comes preconfigured with recommended workspace settings and tasks for Visual Studio Code:
- LSP & Formatting: Auto-formatting on save and real-time Language Server diagnostics via
alya-lang.vscode-alya. - DAP Debugging: Launch configurations in
.vscode/launch.jsonready for interactive step-debugging viaF5. - Predefined Tasks: Press
Ctrl+Shift+Bor run tasks (Test,Lint,Format,Build Docs) directly from the Command Palette.
Contributions are welcome! Please follow these steps:
- Fork the repository and clone it locally
- Install dependencies:
alya install
- Create your feature branch (
git checkout -b feature/my-feature) - Verify tests and formatting before opening a PR:
alya test - Commit your changes (
git commit -m "feat: add feature") and open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.