feat: add sysinfo
This commit is contained in:
47
__linux/sysinfo/src/main.rs
Normal file
47
__linux/sysinfo/src/main.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use sysinfo::{NetworkExt, ProcessExt, System, SystemExt};
|
||||
|
||||
fn main() {
|
||||
let mut sys = System::new_all();
|
||||
|
||||
// We display the disks:
|
||||
println!("=> disk list:");
|
||||
for disk in sys.get_disks() {
|
||||
println!("{:?}", disk);
|
||||
}
|
||||
|
||||
println!("{}", "-".repeat(120));
|
||||
// Network data:
|
||||
for (interface_name, data) in sys.get_networks() {
|
||||
println!("{}: {}/{} B", interface_name, data.get_received(), data.get_transmitted());
|
||||
}
|
||||
|
||||
println!("{}", "-".repeat(120));
|
||||
// Components temperature:
|
||||
for component in sys.get_components() {
|
||||
println!("{:?}", component);
|
||||
}
|
||||
|
||||
println!("{}", "-".repeat(120));
|
||||
// Memory information:
|
||||
println!("total memory: {} KB", sys.get_total_memory());
|
||||
println!("used memory : {} KB", sys.get_used_memory());
|
||||
println!("total swap : {} KB", sys.get_total_swap());
|
||||
println!("used swap : {} KB", sys.get_used_swap());
|
||||
|
||||
println!("{}", "-".repeat(120));
|
||||
// Number of processors
|
||||
println!("NB processors: {}", sys.get_processors().len());
|
||||
|
||||
println!("{}", "-".repeat(120));
|
||||
// To refresh all system information:
|
||||
sys.refresh_all();
|
||||
|
||||
// We show the processes and some of their information:
|
||||
for (pid, process) in sys.get_processes() {
|
||||
println!("- [{}] {} {:?}", pid, process.name(), process.disk_usage());
|
||||
println!(" cmd: {:?}", process.cmd());
|
||||
println!(" exe: {:?}", process.exe());
|
||||
println!(" env: {:?}", process.environ());
|
||||
println!(" cwd: {:?}", process.cwd());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user