8 releases
new 0.1.5 | Mar 10, 2025 |
---|---|
0.1.4 | Mar 10, 2025 |
#107 in Operating systems
189 downloads per month
405KB
7.5K
SLoC
π¦ darwin-metrics
A Rust library providing native access to macOS system metrics through low-level system APIs. This crate offers efficient, safe, and async-capable interfaces for monitoring system resources on macOS.
π Features
π₯οΈ System Monitoring
-
CPU Monitoring
- Per-core usage statistics
- CPU model and frequency information
- System load metrics (user, system, idle)
-
Memory Analysis
- RAM usage and availability
- Swap space monitoring
- Memory pressure levels
-
GPU Information
- Active GPU model detection
- GPU utilization metrics
- VRAM consumption tracking
π Resource Tracking
-
Storage Metrics
- Disk space utilization
- I/O performance monitoring
- Read/write speed tracking
-
Power Management
- Battery status and health
- Charging state detection
- Remaining battery time estimation
-
Thermal Monitoring
- Fan speed readings
- CPU and GPU temperature tracking
- System-wide thermal status
π Additional Features
-
Process Information
- Running process enumeration
- Per-process resource usage
- Parent-child process relationship tracking
- Process tree visualization
-
Network Monitoring
- Interface discovery and state tracking
- Traffic statistics (bytes/packets sent/received)
- Bandwidth calculations
- Async network monitoring
π¦ Installation
Add this to your Cargo.toml
:
[dependencies]
darwin-metrics = "0.1.4"
π§ Requirements
- macOS 10.11 (El Capitan) or later
- Rust 1.85 or later
- Xcode Command Line Tools
π Quick Start
use darwin_metrics::{CPU, Memory, Gpu};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get CPU information
let cpu = CPU::new();
println!("CPU cores: {}", cpu.cores());
println!("CPU usage: {}%", cpu.usage()?);
// Monitor memory
let mut memory = Memory::new()?;
memory.update()?;
println!("Memory used: {:.2} GB", memory.used as f64 / 1_073_741_824.0);
println!("Memory pressure: {:.1}%", memory.pressure_percentage());
// Check GPU status
let gpu = Gpu::new()?;
println!("GPU name: {}", gpu.name()?);
Ok(())
}
π― Feature Flags
All features are enabled by default, but you can selectively enable only what you need:
Flag | Description |
---|---|
battery |
Enable battery monitoring |
cpu |
Enable CPU metrics |
memory |
Enable memory statistics |
gpu |
Enable GPU monitoring |
disk |
Enable storage metrics |
temperature |
Enable thermal monitoring |
async |
Enable async support (requires tokio) |
process_monitoring |
Enable detailed process monitoring |
unstable-tests |
Enable tests that may be unstable in CI |
π Development Status
Currently in active development. See our roadmap for detailed development plans.
Development Progress
β Completed (v0.1.0)
- Initial project setup
- Core architecture and error handling
- CPU monitoring module with frequency data
- Memory monitoring with pressure levels
- GPU information and metrics
- Network interface discovery and traffic stats
- Disk space monitoring
- Process monitoring and hierarchy tracking
- Temperature sensors and fan speed tracking
π§ In Progress (v0.2.0)
- Enhanced async support throughout
- Cross-platform abstractions (Linux/Windows)
- Metrics export to Prometheus/InfluxDB
- Performance optimizations
- Event-based monitoring
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
Setup Instructions:
-
Clone the repository:
git clone https://github.com/sm-moshi/darwin-metrics.git cd darwin-metrics
-
Install dependencies:
xcode-select --install # Install Xcode Command Line Tools
-
Set up the Rust toolchains:
rustup install beta stable rustup component add clippy rustfmt --toolchain beta
Our workflow uses:
- Beta toolchain for linting and formatting
- Stable toolchain for building, testing, and releases
-
Build the project:
cargo build --all-features
-
Run tests:
cargo test --all-features
-
Format and lint your code:
cargo +beta fmt cargo +beta clippy --workspace --all-targets --all-features
π How to Cite
If you use darwin-metrics in your projects, please include one of the following attributions:
Citation Formats
π» For Software Projects
This project uses darwin-metrics (https://github.com/sm-moshi/darwin-metrics) by Stuart Meya.
π For Documentation or Technical Writing
darwin-metrics: A Rust library for native macOS system metrics, developed by Stuart Meya.
GitHub repository: https://github.com/sm-moshi/darwin-metrics
π For Academic or Research Use
Meya, S. (2025). darwin-metrics: A Rust library for native macOS system metrics.
GitHub repository: https://github.com/sm-moshi/darwin-metrics
For more detailed attribution requirements, please see the NOTICE file.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Apple's IOKit, Foundation, Core Foundation, and Metal documentation
- objc2 crate by Mads Marquart
- The Rust and Swift communities
- Contributors to the core dependencies
Dependencies
~15β27MB
~394K SLoC