valpackett / systemstat

Rust library for getting system information | also on https://codeberg.org/valpackett/systemstat
https://crates.io/crates/systemstat
The Unlicense
610 stars 71 forks source link

What is load average? #123

Closed WhyFenceCode closed 4 months ago

WhyFenceCode commented 4 months ago

I assume it is the current amount of cpu load, but i can not get it to work. It constantly returns 0 using this code:

fn get_cpu_load() -> f32 {
  System::new()
      .load_average()
      .map(|avg| avg.floor())
      .unwrap_or(0.0)
}
valpackett commented 4 months ago

I'm not sure how that example could even compile since load_average returns a struct with 3 values (one, five and fifteen), not a single f32 :)

You must be new to unix if you haven't heard of load average before. You always see it in top and similar tools. It's basically the average number of processes in actively running state over the last 1, 5, and 15 minutes. If you aren't running anything intensive, it should be under 1.0. On my machine right now it is 0.72, 0.62, 0.79. A quick web search returns a helpful wikipedia article.

You probably want to measure load yourself, over a shorter time period:

https://github.com/valpackett/systemstat/blob/cbd9c1638b792d1819479f0c2baa5840f65af727/examples/info.rs#L98-L107

(and no, there is no such thing as "just load in this moment", that just doesn't make sense. it's always a measurement taken over some time period)