#linux #monitoring #meter

self-meter

A tiny library to measure resource usage of the process it’s used in

8 releases (4 breaking)

Uses old Rust 2015

0.6.0 May 24, 2017
0.5.0 Apr 7, 2017
0.4.4 Apr 3, 2017
0.4.3 Mar 30, 2017
0.1.0 Sep 27, 2016

#3 in #meter

Download history 69/week @ 2021-04-04 59/week @ 2021-04-11 34/week @ 2021-04-18 20/week @ 2021-04-25 41/week @ 2021-05-02 29/week @ 2021-05-09 20/week @ 2021-05-16 20/week @ 2021-05-23 16/week @ 2021-05-30 39/week @ 2021-06-06 30/week @ 2021-06-13 26/week @ 2021-06-20 30/week @ 2021-06-27 39/week @ 2021-07-04 59/week @ 2021-07-11 39/week @ 2021-07-18

237 downloads per month
Used in 3 crates (via self-meter-http)

MIT/Apache

31KB
652 lines

Self-Meter

Status:beta
Documentation:https://docs.rs/self-meter/

A tiny library to measure resource usage of the process it's used in. Currently it measures:

  • Memory Usage
  • CPU Usage with breakdown by each thread
  • Disk Usage

More metrics might be added later. Currently, library supports only linux, but pull requests for other platforms are welcome.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

A tiny library to measure resource usage of the process it's used in. Currently it measures:

  • Memory Usage
  • CPU Usage with breakdown by each thread
  • Disk Usage

More metrics might be added later. Currently, library supports only linux, but pull requests for other platforms are welcome.

Example


# use std::io::{Write, stderr};
# use std::time::Duration;
# use std::thread::sleep;
# use std::collections::BTreeMap;

fn main() {
   let mut meter = self_meter::Meter::new(Duration::new(1, 0)).unwrap();
   meter.track_current_thread("main");
   loop {
       meter.scan()
           .map_err(|e| writeln!(&mut stderr(), "Scan error: {}", e)).ok();
       println!("Report: {:#?}", meter.report());
       println!("Threads: {:#?}",
           meter.thread_report().map(|x| x.collect::<BTreeMap<_,_>>()));
       // Put your task here
       // ...
       //
       sleep(Duration::new(1, 0));
   }
}

Dependencies

~0.6–1.3MB
~31K SLoC