| Crates.io | darwin-metrics |
| lib.rs | darwin-metrics |
| version | 0.1.5 |
| created_at | 2025-03-09 18:15:52.646527+00 |
| updated_at | 2025-03-10 15:44:02.520795+00 |
| description | A Rust library exposing native macOS system metrics |
| homepage | https://sm-moshi.github.io/darwin-metrics |
| repository | https://github.com/sm-moshi/darwin-metrics |
| max_upload_size | |
| id | 1585712 |
| size | 1,126,427 |
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.
Add this to your Cargo.toml:
[dependencies]
darwin-metrics = "0.1.5"
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(())
}
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 |
Currently in active development. See our roadmap for detailed development plans.
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.
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:
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
If you use darwin-metrics in your projects, please include one of the following attributions:
This project uses darwin-metrics (https://github.com/sm-moshi/darwin-metrics) by Stuart Meya.
darwin-metrics: A Rust library for native macOS system metrics, developed by Stuart Meya.
GitHub repository: https://github.com/sm-moshi/darwin-metrics
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.
This project is licensed under the MIT License - see the LICENSE file for details.