sysinfo是Rust编写的用于获取系统信息的库。
支持以下操作系统
AndroidiOSLinuxmacOSRaspberryPiWindows示例
usesysinfo::{NetworkExt,NetworksExt,ProcessExt,System,SystemExt};//Pleasenotethatweuse"new_all"toensurethatalllistof//components,networkinterfaces,disksandusersarealready//filled!letmutsys=System::new_all();//Firstweupdateallinformationofour`System`struct.sys.refresh_all();//Wedisplayalldisks'information:println!("=>disks:");fordiskinsys.disks(){println!("{:?}",disk);}//Networkinterfacesname,datareceivedanddatatransmitted:println!("=>networks:");for(interface_name,data)insys.networks(){println!("{}:{}/{}B",interface_name,data.received(),data.transmitted());}//Componentstemperature:println!("=>components:");forcomponentinsys.components(){println!("{:?}",component);}println!("=>system:");//RAMandswapinformation:println!("totalmemory:{}KB",sys.total_memory());println!("usedmemory:{}KB",sys.used_memory());println!("totalswap:{}KB",sys.total_swap());println!("usedswap:{}KB",sys.used_swap());//Displaysysteminformation:println!("Systemname:{:?}",sys.name());println!("Systemkernelversion:{:?}",sys.kernel_version());println!("SystemOSversion:{:?}",sys.os_version());println!("Systemhostname:{:?}",sys.host_name());//Numberofprocessors:println!("NBprocessors:{}",sys.processors().len());//DisplayprocessesID,namenadiskusage:for(pid,process)insys.processes(){println!("[{}]{}{:?}",pid,process.name(),process.disk_usage());}
评论