pub trait SystemExt: Sized + Debug + Default + Send + Sync {
    const IS_SUPPORTED: bool;
    const SUPPORTED_SIGNALS: &'static [Signal];
Show 50 methods fn new_with_specifics(refreshes: RefreshKind) -> Self; fn refresh_memory(&mut self); fn refresh_cpu_specifics(&mut self, refresh_kind: CpuRefreshKind); fn refresh_components_list(&mut self); fn refresh_processes_specifics(&mut self, refresh_kind: ProcessRefreshKind); fn refresh_process_specifics(
        &mut self,
        pid: Pid,
        refresh_kind: ProcessRefreshKind
    ) -> bool; fn refresh_disks_list(&mut self); fn refresh_users_list(&mut self); fn processes(&self) -> &HashMap<Pid, Process>; fn process(&self, pid: Pid) -> Option<&Process>; fn global_cpu_info(&self) -> &Cpu; fn cpus(&self) -> &[Cpu]; fn physical_core_count(&self) -> Option<usize>; fn total_memory(&self) -> u64; fn free_memory(&self) -> u64; fn available_memory(&self) -> u64; fn used_memory(&self) -> u64; fn total_swap(&self) -> u64; fn free_swap(&self) -> u64; fn used_swap(&self) -> u64; fn components(&self) -> &[Component]; fn components_mut(&mut self) -> &mut [Component]; fn disks(&self) -> &[Disk]; fn users(&self) -> &[User]; fn disks_mut(&mut self) -> &mut [Disk]; fn networks(&self) -> &Networks; fn networks_mut(&mut self) -> &mut Networks; fn uptime(&self) -> u64; fn boot_time(&self) -> u64; fn load_average(&self) -> LoadAvg; fn name(&self) -> Option<String>; fn kernel_version(&self) -> Option<String>; fn os_version(&self) -> Option<String>; fn long_os_version(&self) -> Option<String>; fn host_name(&self) -> Option<String>; fn new() -> Self { ... } fn new_all() -> Self { ... } fn refresh_specifics(&mut self, refreshes: RefreshKind) { ... } fn refresh_all(&mut self) { ... } fn refresh_system(&mut self) { ... } fn refresh_cpu(&mut self) { ... } fn refresh_components(&mut self) { ... } fn refresh_processes(&mut self) { ... } fn refresh_process(&mut self, pid: Pid) -> bool { ... } fn refresh_disks(&mut self) { ... } fn refresh_networks(&mut self) { ... } fn refresh_networks_list(&mut self) { ... } fn processes_by_name<'a>(
        &'a self,
        name: &'a str
    ) -> Box<dyn Iterator<Item = &'a Process> + 'a> { ... } fn processes_by_exact_name<'a>(
        &'a self,
        name: &'a str
    ) -> Box<dyn Iterator<Item = &'a Process> + 'a> { ... } fn get_user_by_id(&self, user_id: &Uid) -> Option<&User> { ... }
}
Expand description

Contains all the methods of the System type.

Required Associated Constants

Returns true if this OS is supported. Please refer to the crate-level documentation to get the list of supported OSes.

use sysinfo::{System, SystemExt};

if System::IS_SUPPORTED {
    println!("This OS is supported!");
} else {
    println!("This OS isn't supported (yet?).");
}

Returns the list of the supported signals on this system (used by ProcessExt::kill_with).

use sysinfo::{System, SystemExt};

println!("supported signals: {:?}", System::SUPPORTED_SIGNALS);

Required Methods

Creates a new System instance and refresh the data corresponding to the given RefreshKind.

use sysinfo::{RefreshKind, System, SystemExt};

// We want everything except disks.
let mut system = System::new_with_specifics(RefreshKind::everything().without_disks_list());

assert_eq!(system.disks().len(), 0);
assert!(system.processes().len() > 0);

// If you want the disks list afterwards, just call the corresponding
// "refresh_disks_list":
system.refresh_disks_list();
let disks = system.disks();

Refreshes RAM and SWAP usage.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_memory();

Refreshes CPUs specific information.

Please note that it doesn’t recompute disks list, components list, network interfaces list nor users list.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_all();

Refreshes components list.

use sysinfo::{System, SystemExt};

let mut s = System::new();
s.refresh_components_list();

Gets all processes and updates the specified information.

⚠️ On Linux, sysinfo keeps the stat files open by default. You can change this behaviour by using set_open_files_limit.

use sysinfo::{ProcessRefreshKind, System, SystemExt};

let mut s = System::new_all();
s.refresh_processes_specifics(ProcessRefreshKind::new());

Refreshes only the process corresponding to pid. Returns false if the process doesn’t exist (it will NOT be removed from the processes if it doesn’t exist anymore). If it isn’t listed yet, it’ll be added.

use sysinfo::{Pid, ProcessRefreshKind, System, SystemExt};

let mut s = System::new_all();
s.refresh_process_specifics(Pid::from(1337), ProcessRefreshKind::new());

The disk list will be emptied then completely recomputed.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_disks_list();

Refreshes users list.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_users_list();

Returns the process list.

use sysinfo::{ProcessExt, System, SystemExt};

let s = System::new_all();
for (pid, process) in s.processes() {
    println!("{} {}", pid, process.name());
}

Returns the process corresponding to the given pid or None if no such process exists.

use sysinfo::{Pid, ProcessExt, System, SystemExt};

let s = System::new_all();
if let Some(process) = s.process(Pid::from(1337)) {
    println!("{}", process.name());
}

Returns “global” cpus information (aka the addition of all the CPUs).

To have up-to-date information, you need to call SystemExt::refresh_cpu or SystemExt::refresh_specifics with cpu enabled.

use sysinfo::{CpuRefreshKind, CpuExt, RefreshKind, System, SystemExt};

let s = System::new_with_specifics(
    RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);
println!("{}%", s.global_cpu_info().cpu_usage());

Returns the list of the CPUs.

By default, the list of cpus is empty until you call SystemExt::refresh_cpu or SystemExt::refresh_specifics with cpu enabled.

use sysinfo::{CpuRefreshKind, CpuExt, RefreshKind, System, SystemExt};

let s = System::new_with_specifics(
    RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
);
for cpu in s.cpus() {
    println!("{}%", cpu.cpu_usage());
}

Returns the number of physical cores on the CPU or None if it couldn’t get it.

In case there are multiple CPUs, it will combine the physical core count of all the CPUs.

Important: this information is computed every time this function is called.

use sysinfo::{CpuExt, System, SystemExt};

let s = System::new();
println!("{:?}", s.physical_core_count());

Returns the RAM size in KB.

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("{} KB", s.total_memory());

Returns the amount of free RAM in KB.

Generally, “free” memory refers to unallocated memory whereas “available” memory refers to memory that is available for (re)use.

Side note: Windows doesn’t report “free” memory so this method returns the same value as get_available_memory.

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("{} KB", s.free_memory());

Returns the amount of available RAM in KB.

Generally, “free” memory refers to unallocated memory whereas “available” memory refers to memory that is available for (re)use.

⚠️ Windows and FreeBSD don’t report “available” memory so SystemExt::free_memory returns the same value as this method.

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("{} KB", s.available_memory());

Returns the amount of used RAM in KB.

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("{} KB", s.used_memory());

Returns the SWAP size in KB.

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("{} KB", s.total_swap());

Returns the amount of free SWAP in KB.

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("{} KB", s.free_swap());

Returns the amount of used SWAP in KB.

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("{} KB", s.used_swap());

Returns the components list.

use sysinfo::{ComponentExt, System, SystemExt};

let s = System::new_all();
for component in s.components() {
    println!("{}: {}°C", component.label(), component.temperature());
}

Returns a mutable components list.

use sysinfo::{ComponentExt, System, SystemExt};

let mut s = System::new_all();
for component in s.components_mut() {
    component.refresh();
}

Returns the disks list.

use sysinfo::{DiskExt, System, SystemExt};

let s = System::new_all();
for disk in s.disks() {
    println!("{:?}", disk.name());
}

Returns the users list.

use sysinfo::{System, SystemExt, UserExt};

let mut s = System::new_all();
for user in s.users() {
    println!("{} is in {} groups", user.name(), user.groups().len());
}

Returns the disks list.

use sysinfo::{DiskExt, System, SystemExt};

let mut s = System::new_all();
for disk in s.disks_mut() {
    disk.refresh();
}

Returns the network interfaces object.

use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};

let s = System::new_all();
let networks = s.networks();
for (interface_name, data) in networks {
    println!(
        "[{}] in: {}, out: {}",
        interface_name,
        data.received(),
        data.transmitted(),
    );
}

Returns a mutable access to network interfaces.

use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};

let mut s = System::new_all();
let networks = s.networks_mut();
networks.refresh_networks_list();

Returns system uptime (in seconds).

use sysinfo::{System, SystemExt};

let s = System::new_all();
println!("System running since {} seconds", s.uptime());

Returns the time (in seconds) when the system booted since UNIX epoch.

use sysinfo::{System, SystemExt};

let s = System::new();
println!("System booted at {} seconds", s.boot_time());

Returns the system load average value.

use sysinfo::{System, SystemExt};

let s = System::new_all();
let load_avg = s.load_average();
println!(
    "one minute: {}%, five minutes: {}%, fifteen minutes: {}%",
    load_avg.one,
    load_avg.five,
    load_avg.fifteen,
);

Returns the system name.

Important: this information is computed every time this function is called.

use sysinfo::{System, SystemExt};

let s = System::new();
println!("OS: {:?}", s.name());

Returns the system’s kernel version.

Important: this information is computed every time this function is called.

use sysinfo::{System, SystemExt};

let s = System::new();
println!("kernel version: {:?}", s.kernel_version());

Returns the system version (e.g. for MacOS this will return 11.1 rather than the kernel version).

Important: this information is computed every time this function is called.

use sysinfo::{System, SystemExt};

let s = System::new();
println!("OS version: {:?}", s.os_version());

Returns the system long os version (e.g “MacOS 11.2 BigSur”).

Important: this information is computed every time this function is called.

use sysinfo::{System, SystemExt};

let s = System::new();
println!("Long OS Version: {:?}", s.long_os_version());

Returns the system hostname based off DNS

Important: this information is computed every time this function is called.

use sysinfo::{System, SystemExt};

let s = System::new();
println!("Hostname: {:?}", s.host_name());

Provided Methods

Creates a new System instance with nothing loaded except the cpus list. If you want to load components, network interfaces or the disks, you’ll have to use the refresh_*_list methods. SystemExt::refresh_networks_list for example.

Use the refresh_all method to update its internal information (or any of the refresh_ method).

use sysinfo::{System, SystemExt};

let s = System::new();

Creates a new System instance with everything loaded.

It is an equivalent of SystemExt::new_with_specifics(RefreshKind::everything()).

use sysinfo::{System, SystemExt};

let s = System::new_all();

Refreshes according to the given RefreshKind. It calls the corresponding “refresh_” methods.

use sysinfo::{ProcessRefreshKind, RefreshKind, System, SystemExt};

let mut s = System::new_all();

// Let's just update networks and processes:
s.refresh_specifics(
    RefreshKind::new().with_networks().with_processes(ProcessRefreshKind::everything()),
);

Refreshes all system, processes, disks and network interfaces information.

Please note that it doesn’t recompute disks list, components list, network interfaces list nor users list.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_all();

Refreshes system information (RAM, swap, CPU usage and components’ temperature).

If you want some more specific refreshes, you might be interested into looking at refresh_memory, refresh_cpu and refresh_components.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_system();

Refreshes CPUs information.

⚠️ Please note that the result will very likely be inaccurate at the first call. You need to call this method at least twice (with a bit of time between each call, like 200ms) to get accurate values as it uses previous results to compute the next value.

Calling this method is the same as calling refresh_cpu_specifics(CpuRefreshKind::everything()).

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_cpu();

Refreshes components’ temperature.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_components();

Gets all processes and updates their information.

It does the same as system.refresh_processes_specifics(ProcessRefreshKind::everything()).

⚠️ On Linux, sysinfo keeps the stat files open by default. You can change this behaviour by using set_open_files_limit.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_processes();

Refreshes only the process corresponding to pid. Returns false if the process doesn’t exist (it will NOT be removed from the processes if it doesn’t exist anymore). If it isn’t listed yet, it’ll be added.

It is the same as calling sys.refresh_process_specifics(pid, ProcessRefreshKind::everything()).

use sysinfo::{Pid, System, SystemExt};

let mut s = System::new_all();
s.refresh_process(Pid::from(1337));

Refreshes the listed disks’ information.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_disks();

Refreshes networks data.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_networks();

It is a shortcut for:

use sysinfo::{NetworksExt, System, SystemExt};

let mut s = System::new_all();
let networks = s.networks_mut();
networks.refresh();

The network list will be updated: removing not existing anymore interfaces and adding new ones.

use sysinfo::{System, SystemExt};

let mut s = System::new_all();
s.refresh_networks_list();

This is a shortcut for:

use sysinfo::{NetworksExt, System, SystemExt};

let mut s = System::new_all();
let networks = s.networks_mut();
networks.refresh_networks_list();

Returns an iterator of process containing the given name.

If you want only the processes with exactly the given name, take a look at SystemExt::processes_by_exact_name.

use sysinfo::{ProcessExt, System, SystemExt};

let s = System::new_all();
for process in s.processes_by_name("htop") {
    println!("{} {}", process.pid(), process.name());
}

Returns an iterator of processes with exactly the given name.

If you instead want the processes containing name, take a look at SystemExt::processes_by_name.

use sysinfo::{ProcessExt, System, SystemExt};

let s = System::new_all();
for process in s.processes_by_exact_name("htop") {
    println!("{} {}", process.pid(), process.name());
}

Returns the User matching the given user_id.

Important: The user list must be filled before using this method, otherwise it will always return None (through the refresh_* methods).

It is a shorthand for:

let s = System::new_all();
s.users().find(|user| user.id() == user_id);

Full example:

use sysinfo::{Pid, ProcessExt, System, SystemExt};

let mut s = System::new_all();

if let Some(process) = s.process(Pid::from(1337)) {
    if let Some(user_id) = process.user_id() {
        eprintln!("User for process 1337: {:?}", s.get_user_by_id(user_id));
    }
}

Implementors