modkit-node-info
A standalone library for collecting system information about the current node where code is executed.
Purpose
This library provides system information collection without any transport layer dependencies. It can be used by any CyberFabric module that needs to gather information about the execution environment.
Features
- Hardware-Based Node UUID: Permanent UUID derived from machine hardware identifiers with hybrid fallback
- System Information Collection: OS, CPU, memory, GPU, battery, host details with all IP addresses
- System Capabilities Detection: Hardware and OS capabilities with cache metadata
- Cross-Platform: Platform-specific implementations for macOS, Linux, and Windows
- Cache-Aware Capabilities: Each capability includes TTL and fetch timestamp for intelligent caching
Public API
use ;
// Get permanent hardware-based UUID for this machine
let node_id = get_hardware_uuid; // Returns Uuid directly (no Result)
// Create collector
let collector = new;
// Create a Node instance for the current machine
let node = collector.create_current_node;
// Collect system information
let sysinfo = collector.collect_sysinfo?;
// Collect system capabilities (with cache metadata)
let syscap = collector.collect_syscap?;
// Collect both sysinfo and syscap in one call
let = collector.collect_all?;
Hardware UUID
The get_hardware_uuid() function returns a permanent UUID based on the machine's hardware identifiers:
Platform Support
- macOS: Uses
IOPlatformUUIDfrom IOKit (already a UUID) - Linux: Uses
/etc/machine-idor/var/lib/dbus/machine-id(converted to UUID) - Windows: Uses
MachineGuidfrom registry (already a UUID)
Fallback Behavior
If hardware detection fails, returns a hybrid UUID pattern:
- Format:
00000000-0000-0000-xxxx-xxxxxxxxxxxx - Left 8 bytes: All zeros (indicates fallback)
- Right 8 bytes: Random (ensures uniqueness)
Cache TTL Values
System capabilities use different cache TTLs based on change frequency:
| Capability Type | TTL | Reason |
|---|---|---|
| Architecture | 1 hour | Never changes |
| RAM | 5 seconds | Changes frequently |
| CPU | 10 minutes | Rarely changes |
| OS | 2 minutes | Rarely changes |
| GPU | 10 seconds | Can change (hot-plug) |
| Battery | 3 seconds | Very dynamic |
Usage Examples
Basic Usage
use NodeInfoCollector;
let collector = new;
let node = collector.create_current_node;
let sysinfo = collector.collect_sysinfo?;
let syscap = collector.collect_syscap?;
println!;
println!;
println!;
Working with Capabilities
let syscap = collector.collect_syscap?;
for cap in syscap.capabilities
Platform-Specific Features
GPU Detection
NVIDIA GPUs (Linux & Windows):
- Uses NVML (NVIDIA Management Library) via
nvml-wrappercrate - Provides detailed GPU information including memory usage
- Same library used by
nvidia-smi - Gracefully falls back if NVIDIA drivers not present
Other GPUs:
- macOS: Uses
system_profiler SPDisplaysDataTypefor all GPUs - Linux: Falls back to
lspcifor AMD/Intel GPUs - Windows: Falls back to
wmicWin32_VideoController for AMD/Intel GPUs
Detection Strategy:
- Try NVML first for NVIDIA GPUs (Linux/Windows)
- If NVML unavailable or no NVIDIA GPUs found, use platform-specific fallback
- Returns empty list if no GPUs detected
Battery Detection
- Uses
starship-batterycrate for cross-platform battery information - Returns
Nonefor desktop systems without batteries
IP Address Detection
- Detects local IP address used for default route
- Collects all network IPs in HostInfo.ip_addresses
- First IP is the primary one (matches Node.ip_address)
Dependencies
sysinfo- System information collectionmachine-uid- Hardware UUID detectionlocal-ip-address- Local IP detectionstarship-battery- Battery informationnvml-wrapper- NVIDIA GPU detection (Linux & Windows)regex- GPU parsing (macOS)chrono- Timestampsuuid- Node IDs
Usage in Modules
This library is designed to be used by the nodes_registry module and any other module that needs to collect information about the current execution environment.
[]
= { = "../../libs/modkit-node-info" }