pub struct Machine { /* private fields */ }
Expand description

Represents a machine. Currently you can monitor global CPU/Memory usage, processes CPU usage and the Nvidia GPU usage. You can also retrieve information about CPU, disks…

Implementations

Creates a new instance of Machine. If not graphic card it will warn about it but not an error Example

use machine_info::Machine;
let m = Machine::new();

Retrieves full information about the computer Example

use machine_info::Machine;
let m = Machine::new();
println!("{:?}", m.system_info())

The current usage of all graphic cards (if any) Example

use machine_info::Machine;
let m = Machine::new();
println!("{:?}", m.graphics_status())

To calculate the CPU usage of a process we have to keep track in time the process so first we have to register the process. You need to know the PID of your process and use it as parameters. In case you provide an invalid PID it will return error Example

use machine_info::Machine;
let m = Machine::new();
let process_pid = 3218;
m.track_process(process_pid)

Once we dont need to track a process it is recommended to not keep using resources on it. You should know the PID of your process. If the PID was not registered before, it will just do nothing Example

use machine_info::Machine;
let m = Machine::new();
let process_pid = 3218;
m.track_process(process_pid)
m.untrack_process(process_pid)

The CPU usage of all tracked processes since the last call. So if you call it every 10 seconds, you will get the CPU usage during the last 10 seconds. More calls will make the value more accurate but also more expensive Example

use machine_info::Machine;
use std::{thread, time};
 
let m = Machine::new();
m.track_process(3218)
m.track_process(4467)
loop {   
  let status = m.processes_status();
  println!("{:?}", status);
  thread::sleep(time::Duration::from_millis(1000));
}
 

The CPU and memory usage. For the CPU, it is the same as for processes_status. For the memory it returs the amount a this moment Example

use machine_info::Machine;
use std::{thread, time};
 
let m = Machine::new();
m.track_process(3218)
m.track_process(4467)
loop {   
  let status = m.system_status();
  println!("{:?}", status);
  thread::sleep(time::Duration::from_millis(1000));
}
 

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.