wixet-limited / machine-info-rs

Get a basic information from your machine
Apache License 2.0
4 stars 1 forks source link

Application breaks when trying to get cpu usage #1

Closed maxpowel closed 2 years ago

maxpowel commented 2 years ago

Just run this code

use machine_info::Machine;

fn main() {
    let mut m = Machine::new();
    println!("{:?}", m.system_status());

}

And the error returned is:

thread 'main' panicked at 'attempt to multiply with overflow', /home/maxpowel/machine-info-rs/src/monitor.rs:92:21
maxpowel commented 2 years ago

Looks like i32 is not enough for storing the temporal CPU usage variables. My computer uptime command returns

11:26:42 up 7 days, 17:52, 16 users,  load average: 1,18, 1,67, 1,67

and the value from /proc/stat is huge (cannot fit into an i32). Probably just chaning it to something like u64 will prevent this. All of us will be dead when someone keeps a machine up this long time xD.