Skip to content

IVAN-MK7/system_metrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLI tool for monitoring system resources usage, made with Rust 🦀

github Apache

Examples

Interactive CLI usage

cargo run --release -- --help
cargo run --release
cargo build --release
./target/release/system_metrics

Sample output:

{
  "cpu_usage_percent": 7.7,
  "ram_used_mb": 19704,
  "ram_total_mb": 32416,
  "network": {
    "upload_kbps": 3.3,
    "download_kbps": 3.3
  }
}

Library usage

./Cargo.toml:

[dependencies]
system_metrics = { path = "../system_metrics" }
ctrlc = "3.5.2"

Rust code:

use std::{sync::mpsc, time::Duration};

use system_metrics::{TargetNetworkInterface, get_network_interfaces_names, get_system_stats};

// Set up a channel to listen for CTRL+C interrupts,
let (tx, rx) = mpsc::channel();

// and register the handler.
ctrlc::set_handler(move || {
    let _ = tx.send(());
})
.ok();

// Duration to measure the metrics over.
let duration = Duration::from_secs(3);

// Start the monitoring and retrieve the stats once it's done.
// Finish gathering early by pressing CTRL+C.
let system_stats = get_system_stats(TargetNetworkInterface::FirstActive, duration, rx).unwrap();

About

CLI tool for monitoring system resources usage, made with Rust 🦀

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages