pub struct SystemInfo { /* private fields */ }Expand description
Information about the system resources
Implementations§
Source§impl SystemInfo
impl SystemInfo
Sourcepub fn free_memory(&self) -> u64
pub fn free_memory(&self) -> u64
returns the amount of free memory in bytes
Sourcepub fn get_cpu_cores(&self) -> usize
pub fn get_cpu_cores(&self) -> usize
returns the number of cores in the system
Sourcepub fn get_cpu_usage(&self) -> f32
pub fn get_cpu_usage(&self) -> f32
Get the current CPU load as a fraction (0.0 to 1.0)
Sourcepub fn get_free_memory_mb(&self) -> usize
pub fn get_free_memory_mb(&self) -> usize
returns the amount of free memory in MB
Sourcepub fn get_ram_memory_usage(&self) -> f32
pub fn get_ram_memory_usage(&self) -> f32
returns the normalized (0.0 to 1.0) memory usage
Sourcepub fn get_current_load(&self) -> f32
pub fn get_current_load(&self) -> f32
Get the current system load as a fraction (0.0 to 1.0)
Sourcepub fn memory_usage(&self) -> f32
pub fn memory_usage(&self) -> f32
Get memory usage in bytes
Methods from Deref<Target = System>§
Sourcepub fn processes(&self) -> &HashMap<Pid, Process>
pub fn processes(&self) -> &HashMap<Pid, Process>
Returns the process list.
use sysinfo::System;
let s = System::new_all();
for (pid, process) in s.processes() {
println!("{} {:?}", pid, process.name());
}Sourcepub fn process(&self, pid: Pid) -> Option<&Process>
pub fn process(&self, pid: Pid) -> Option<&Process>
Returns the process corresponding to the given pid or None if no such process exists.
use sysinfo::{Pid, System};
let s = System::new_all();
if let Some(process) = s.process(Pid::from(1337)) {
println!("{:?}", process.name());
}Sourcepub fn processes_by_name<'a, 'b>(
&'a self,
name: &'b OsStr,
) -> impl Iterator<Item = &'a Process> + 'bwhere
'a: 'b,
pub fn processes_by_name<'a, 'b>(
&'a self,
name: &'b OsStr,
) -> impl Iterator<Item = &'a Process> + 'bwhere
'a: 'b,
Returns an iterator of process containing the given name.
If you want only the processes with exactly the given name, take a look at
System::processes_by_exact_name.
⚠️ Important ⚠️
On Linux, there are two things to know about processes’ name:
- It is limited to 15 characters.
- It is not always the exe name.
use sysinfo::System;
let s = System::new_all();
for process in s.processes_by_name("htop".as_ref()) {
println!("{} {:?}", process.pid(), process.name());
}Sourcepub fn processes_by_exact_name<'a, 'b>(
&'a self,
name: &'b OsStr,
) -> impl Iterator<Item = &'a Process> + 'bwhere
'a: 'b,
pub fn processes_by_exact_name<'a, 'b>(
&'a self,
name: &'b OsStr,
) -> impl Iterator<Item = &'a Process> + 'bwhere
'a: 'b,
Returns an iterator of processes with exactly the given name.
If you instead want the processes containing name, take a look at
System::processes_by_name.
⚠️ Important ⚠️
On Linux, there are two things to know about processes’ name:
- It is limited to 15 characters.
- It is not always the exe name.
use sysinfo::System;
let s = System::new_all();
for process in s.processes_by_exact_name("htop".as_ref()) {
println!("{} {:?}", process.pid(), process.name());
}Sourcepub fn global_cpu_usage(&self) -> f32
pub fn global_cpu_usage(&self) -> f32
Returns “global” CPUs usage (aka the addition of all the CPUs).
To have up-to-date information, you need to call System::refresh_cpu_specifics or
System::refresh_specifics with cpu enabled.
use sysinfo::{CpuRefreshKind, RefreshKind, System};
let mut s = System::new_with_specifics(
RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
);
// Wait a bit because CPU usage is based on diff.
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
// Refresh CPUs again to get actual value.
s.refresh_cpu_usage();
println!("{}%", s.global_cpu_usage());Sourcepub fn cpus(&self) -> &[Cpu]
pub fn cpus(&self) -> &[Cpu]
Returns the list of the CPUs.
By default, the list of CPUs is empty until you call System::refresh_cpu_specifics or
System::refresh_specifics with cpu enabled.
use sysinfo::{CpuRefreshKind, RefreshKind, System};
let mut s = System::new_with_specifics(
RefreshKind::nothing().with_cpu(CpuRefreshKind::everything()),
);
// Wait a bit because CPU usage is based on diff.
std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);
// Refresh CPUs again to get actual value.
s.refresh_cpu_usage();
for cpu in s.cpus() {
println!("{}%", cpu.cpu_usage());
}Sourcepub fn total_memory(&self) -> u64
pub fn total_memory(&self) -> u64
Returns the RAM size in bytes.
use sysinfo::System;
let s = System::new_all();
println!("{} bytes", s.total_memory());On Linux, if you want to see this information with the limit of your cgroup, take a look
at cgroup_limits.
Sourcepub fn free_memory(&self) -> u64
pub fn free_memory(&self) -> u64
Returns the amount of free RAM in bytes.
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 available_memory.
use sysinfo::System;
let s = System::new_all();
println!("{} bytes", s.free_memory());Sourcepub fn available_memory(&self) -> u64
pub fn available_memory(&self) -> u64
Returns the amount of available RAM in bytes.
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 System::free_memory
returns the same value as this method.
use sysinfo::System;
let s = System::new_all();
println!("{} bytes", s.available_memory());Sourcepub fn used_memory(&self) -> u64
pub fn used_memory(&self) -> u64
Returns the amount of used RAM in bytes.
use sysinfo::System;
let s = System::new_all();
println!("{} bytes", s.used_memory());Sourcepub fn total_swap(&self) -> u64
pub fn total_swap(&self) -> u64
Returns the SWAP size in bytes.
use sysinfo::System;
let s = System::new_all();
println!("{} bytes", s.total_swap());Sourcepub fn free_swap(&self) -> u64
pub fn free_swap(&self) -> u64
Returns the amount of free SWAP in bytes.
use sysinfo::System;
let s = System::new_all();
println!("{} bytes", s.free_swap());Sourcepub fn used_swap(&self) -> u64
pub fn used_swap(&self) -> u64
Returns the amount of used SWAP in bytes.
use sysinfo::System;
let s = System::new_all();
println!("{} bytes", s.used_swap());Sourcepub fn cgroup_limits(&self) -> Option<CGroupLimits>
pub fn cgroup_limits(&self) -> Option<CGroupLimits>
Retrieves the limits for the current cgroup (if any), otherwise it returns None.
This information is computed every time the method is called.
⚠️ You need to have run refresh_memory at least once before
calling this method.
⚠️ This method is only implemented for Linux. It always returns None for all other
systems.
use sysinfo::System;
let s = System::new_all();
println!("limits: {:?}", s.cgroup_limits());Trait Implementations§
Source§impl Clone for SystemInfo
impl Clone for SystemInfo
Source§fn clone(&self) -> SystemInfo
fn clone(&self) -> SystemInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SystemInfo
impl Debug for SystemInfo
Source§impl Default for SystemInfo
impl Default for SystemInfo
Source§impl Deref for SystemInfo
impl Deref for SystemInfo
Source§impl Display for SystemInfo
impl Display for SystemInfo
Auto Trait Implementations§
impl Freeze for SystemInfo
impl RefUnwindSafe for SystemInfo
impl Send for SystemInfo
impl Sync for SystemInfo
impl Unpin for SystemInfo
impl UnwindSafe for SystemInfo
Blanket Implementations§
Source§impl<T> AsWeight<T> for Twhere
T: Clone + IntoWeight<T>,
impl<T> AsWeight<T> for Twhere
T: Clone + IntoWeight<T>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more