add sysinfo

This commit is contained in:
2021-12-19 18:10:16 +08:00
parent a4466eefaa
commit 55045c0a71
2 changed files with 26 additions and 1 deletions

View File

@@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
reqwest = "0.11.7"
tokio = { version = "1.15.0", features = ["full"] }
sysinfo = "0.22.2"

View File

@@ -1,5 +1,29 @@
use sysinfo::{DiskExt, System, SystemExt};
#[tokio::main]
async fn main() {
// TODO get system info and record to SLS
let mut sys = System::new_all();
sys.refresh_all();
let host_name = sys.host_name().unwrap_or_else(|| "unknown".into());
// We display all disks' information:
println!("=> disks:");
for disk in sys.disks() {
println!("{:?}", disk.mount_point());
}
println!("=> system:");
// RAM and swap information:
println!("total memory: {} KB", sys.total_memory());
println!("used memory : {} KB", sys.used_memory());
println!("total swap : {} KB", sys.total_swap());
println!("used swap : {} KB", sys.used_swap());
// Display system information:
println!("System name: {:?}", sys.name());
println!("System kernel version: {:?}", sys.kernel_version());
println!("System OS version: {:?}", sys.os_version());
println!("System host name: {:?}", sys.host_name());
}