Skip to content

Latest commit

Β 

History

28 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

sysinfo

CI License Alya Package Version

Cross-platform system information: OS, CPU, memory, disk, host, timezone, power, process, env, load, and locale for Alya


🌟 Features

  • πŸ–₯️ 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.0 on Windows)
  • 🌍 Locale Detection: Native locale API with LANGUAGE/LC_*/LANG fallback, 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

πŸ“ Project Architecture

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.


πŸ“¦ Installation

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

Package Features

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-features

πŸš€ Quick Start

import "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()

πŸ“– API Reference

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.


πŸ–₯️ Platform Coverage

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

πŸ§ͺ Running Tests & Benchmarks

Run the automated test suite using alya test:

alya test

Generate static API documentation:

alya doc . -o docs --markdown

Run the benchmark suite:

alya run benches/bench_basic.alya

Run the example demo:

alya run examples/demo.alya

Check code formatting:

alya fmt . --check

Run static code linter:

alya lint . --check

πŸ’» Developer Tooling & VS Code Integration

This 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.json ready for interactive step-debugging via F5.
  • Predefined Tasks: Press Ctrl+Shift+B or run tasks (Test, Lint, Format, Build Docs) directly from the Command Palette.

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository and clone it locally
  2. Install dependencies:
    alya install
  3. Create your feature branch (git checkout -b feature/my-feature)
  4. Verify tests and formatting before opening a PR:
    alya test
  5. Commit your changes (git commit -m "feat: add feature") and open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Cross-platform system information: OS, CPU, memory, disk, host, timezone, power, process, env, load, and locale for Alya

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages