sysinfo - Which Operating System are we running on?



examples/other/system-info/Cargo.toml
[package]
name = "system-info"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
sysinfo = "0.29"

examples/other/system-info/src/main.rs
use sysinfo::{System, SystemExt};

fn main() {
    let sys = System::new_all();

    println!("System name:             {}", sys.name().unwrap());
    println!("System kernel version:   {}", sys.kernel_version().unwrap());
    println!("System OS version:       {}", sys.os_version().unwrap());
    println!("System host name:        {}", sys.host_name().unwrap());
    println!();

    println!("NB CPUs:                 {}", sys.cpus().len());
    println!();

    println!("total memory: {} bytes", sys.total_memory());
    println!("used memory : {} bytes", sys.used_memory());
    println!("total swap  : {} bytes", sys.total_swap());
    println!("used swap   : {} bytes", sys.used_swap());
}

System name:             Ubuntu
System kernel version:   6.5.0-10-generic
System OS version:       23.10
System host name:        code-maven

NB CPUs:                 16

total memory: 29166940160 bytes
used memory : 10617876480 bytes
total swap  : 8589930496 bytes
used swap   : 0 bytes