#metrics #swift #cpu-memory #cpu-gpu #macos #process-information #system

sys darwin-metrics

A Rust library exposing native macOS system metrics

8 releases

new 0.1.5 Mar 10, 2025
0.1.4 Mar 10, 2025

#107 in Operating systems

Download history

189 downloads per month

MIT license

405KB
7.5K SLoC

πŸ¦€ darwin-metrics

Crates.io Documentation License: MIT Build Status Crates.io Downloads

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:

  1. Clone the repository:

    git clone https://github.com/sm-moshi/darwin-metrics.git
    cd darwin-metrics
    
  2. Install dependencies:

    xcode-select --install  # Install Xcode Command Line Tools
    
  3. 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
  4. Build the project:

    cargo build --all-features
    
  5. Run tests:

    cargo test --all-features
    
  6. 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

Dependencies

~15–27MB
~394K SLoC