Trait sysinfo::SystemExt [−][src]
Contains all the methods of the System
type.
Required methods
fn new_with_specifics(refreshes: RefreshKind) -> Self
[src]
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.get_disks().len(), 0); assert!(system.get_processes().len() > 0); // If you want the disks list afterwards, just call the corresponding // "refresh_disks_list": system.refresh_disks_list(); let disks = system.get_disks();
fn refresh_memory(&mut self)
[src]
Refreshes RAM and SWAP usage.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_memory();
fn refresh_cpu(&mut self)
[src]
Refreshes CPU usage.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_cpu();
fn refresh_components_list(&mut self)
[src]
Refreshes components list.
use sysinfo::{System, SystemExt}; let mut s = System::new(); s.refresh_components_list();
fn refresh_processes(&mut self)
[src]
Gets all processes and updates their information.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_processes();
fn refresh_process(&mut self, pid: Pid) -> bool
[src]
Refreshes only the process corresponding to pid
. Returns false
if the process doesn’t
exist. If it isn’t listed yet, it’ll be added.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_process(1337);
fn refresh_disks_list(&mut self)
[src]
The disk list will be emptied then completely recomputed.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_disks_list();
fn refresh_users_list(&mut self)
[src]
Refreshes users list.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_users_list();
fn get_processes(&self) -> &HashMap<Pid, Process>
[src]
Returns the process list.
use sysinfo::{ProcessExt, System, SystemExt}; let s = System::new_all(); for (pid, process) in s.get_processes() { println!("{} {}", pid, process.name()); }
fn get_process(&self, pid: Pid) -> Option<&Process>
[src]
Returns the process corresponding to the given pid or None
if no such process exists.
use sysinfo::{ProcessExt, System, SystemExt}; let s = System::new_all(); if let Some(process) = s.get_process(1337) { println!("{}", process.name()); }
fn get_global_processor_info(&self) -> &Processor
[src]
Returns “global” processors information (aka the addition of all the processors).
use sysinfo::{ProcessorExt, System, SystemExt}; let s = System::new(); println!("{}%", s.get_global_processor_info().get_cpu_usage());
fn get_processors(&self) -> &[Processor]
[src]
Returns the list of the processors.
use sysinfo::{ProcessorExt, System, SystemExt}; let s = System::new(); for processor in s.get_processors() { println!("{}%", processor.get_cpu_usage()); }
fn get_physical_core_count(&self) -> Option<usize>
[src]
Returns the number of physical cores on the processor 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::{ProcessorExt, System, SystemExt}; let s = System::new(); println!("{:?}", s.get_physical_core_count());
fn get_total_memory(&self) -> u64
[src]
Returns the RAM size in kB.
use sysinfo::{System, SystemExt}; let s = System::new_all(); println!("{} kB", s.get_total_memory());
fn get_free_memory(&self) -> u64
[src]
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.get_free_memory());
fn get_available_memory(&self) -> u64
[src]
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.
Side note: Windows doesn’t report “free” memory so
get_free_memory
returns the same value as this method.
use sysinfo::{System, SystemExt}; let s = System::new_all(); println!("{} kB", s.get_available_memory());
fn get_used_memory(&self) -> u64
[src]
Returns the amound of used RAM in kB.
use sysinfo::{System, SystemExt}; let s = System::new_all(); println!("{} kB", s.get_used_memory());
fn get_total_swap(&self) -> u64
[src]
Returns the SWAP size in kB.
use sysinfo::{System, SystemExt}; let s = System::new_all(); println!("{} kB", s.get_total_swap());
fn get_free_swap(&self) -> u64
[src]
Returns the amount of free SWAP in kB.
use sysinfo::{System, SystemExt}; let s = System::new_all(); println!("{} kB", s.get_free_swap());
fn get_used_swap(&self) -> u64
[src]
Returns the amount of used SWAP in kB.
use sysinfo::{System, SystemExt}; let s = System::new_all(); println!("{} kB", s.get_used_swap());
fn get_components(&self) -> &[Component]
[src]
Returns the components list.
use sysinfo::{ComponentExt, System, SystemExt}; let s = System::new_all(); for component in s.get_components() { println!("{}: {}°C", component.get_label(), component.get_temperature()); }
fn get_components_mut(&mut self) -> &mut [Component]
[src]
Returns a mutable components list.
use sysinfo::{ComponentExt, System, SystemExt}; let mut s = System::new_all(); for component in s.get_components_mut() { component.refresh(); }
fn get_disks(&self) -> &[Disk]
[src]
Returns the disks list.
use sysinfo::{DiskExt, System, SystemExt}; let s = System::new_all(); for disk in s.get_disks() { println!("{:?}", disk.get_name()); }
fn get_users(&self) -> &[User]
[src]
Returns the users list.
use sysinfo::{System, SystemExt, UserExt}; let mut s = System::new_all(); for user in s.get_users() { println!("{} is in {} groups", user.get_name(), user.get_groups().len()); }
fn get_disks_mut(&mut self) -> &mut [Disk]
[src]
Returns the disks list.
use sysinfo::{DiskExt, System, SystemExt}; let mut s = System::new_all(); for disk in s.get_disks_mut() { disk.refresh(); }
fn get_networks(&self) -> &Networks
[src]
Returns the network interfaces object.
use sysinfo::{NetworkExt, NetworksExt, System, SystemExt}; let s = System::new_all(); let networks = s.get_networks(); for (interface_name, data) in networks { println!( "[{}] in: {}, out: {}", interface_name, data.get_received(), data.get_transmitted(), ); }
fn get_networks_mut(&mut self) -> &mut Networks
[src]
Returns a mutable access to network interfaces.
use sysinfo::{NetworkExt, NetworksExt, System, SystemExt}; let mut s = System::new_all(); let networks = s.get_networks_mut(); networks.refresh_networks_list();
fn get_uptime(&self) -> u64
[src]
Returns system uptime (in seconds).
use sysinfo::{System, SystemExt}; let s = System::new_all(); println!("System running since {} seconds", s.get_uptime());
fn get_boot_time(&self) -> u64
[src]
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.get_boot_time());
fn get_load_average(&self) -> LoadAvg
[src]
Returns the system load average value.
use sysinfo::{System, SystemExt}; let s = System::new_all(); let load_avg = s.get_load_average(); println!( "one minute: {}%, five minutes: {}%, fifteen minutes: {}%", load_avg.one, load_avg.five, load_avg.fifteen, );
fn get_name(&self) -> Option<String>
[src]
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.get_name());
fn get_kernel_version(&self) -> Option<String>
[src]
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.get_kernel_version());
fn get_os_version(&self) -> Option<String>
[src]
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.get_os_version());
fn get_long_os_version(&self) -> Option<String>
[src]
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.get_long_os_version());
fn get_host_name(&self) -> Option<String>
[src]
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.get_host_name());
Provided methods
fn new() -> Self
[src]
Creates a new System
instance with nothing loaded except the processors 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();
fn new_all() -> Self
[src]
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();
fn refresh_specifics(&mut self, refreshes: RefreshKind)
[src]
Refreshes according to the given RefreshKind
. It calls the corresponding
“refresh_” methods.
use sysinfo::{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());
fn refresh_system(&mut self)
[src]
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();
fn refresh_components(&mut self)
[src]
Refreshes components’ temperature.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_components();
fn refresh_disks(&mut self)
[src]
Refreshes the listed disks’ information.
use sysinfo::{System, SystemExt}; let mut s = System::new_all(); s.refresh_disks();
fn refresh_networks(&mut self)
[src]
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.get_networks_mut(); networks.refresh();
fn refresh_networks_list(&mut self)
[src]
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.get_networks_mut(); networks.refresh_networks_list();
fn refresh_all(&mut self)
[src]
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();
fn get_process_by_name(&self, name: &str) -> Vec<&Process>
[src]
Returns a list of process containing the given name
.
use sysinfo::{ProcessExt, System, SystemExt}; let s = System::new_all(); for process in s.get_process_by_name("htop") { println!("{} {}", process.pid(), process.name()); }