From 084a74f9c7486010b70b2618bc0fc5ea76ee97cb Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 17 Oct 2020 12:38:59 +0800 Subject: [PATCH] feat: add sysinfo --- __linux/sysinfo/Cargo.lock | 208 ++++++++++++++++++++++++++++++++++++ __linux/sysinfo/Cargo.toml | 12 +++ __linux/sysinfo/src/main.rs | 47 ++++++++ 3 files changed, 267 insertions(+) create mode 100644 __linux/sysinfo/Cargo.lock create mode 100644 __linux/sysinfo/Cargo.toml create mode 100644 __linux/sysinfo/src/main.rs diff --git a/__linux/sysinfo/Cargo.lock b/__linux/sysinfo/Cargo.lock new file mode 100644 index 0000000..4efbfa7 --- /dev/null +++ b/__linux/sysinfo/Cargo.lock @@ -0,0 +1,208 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "crossbeam-channel" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" +dependencies = [ + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "maybe-uninit", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if", + "lazy_static", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "hermit-abi" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +dependencies = [ + "libc", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" + +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + +[[package]] +name = "memoffset" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" +dependencies = [ + "autocfg", +] + +[[package]] +name = "ntapi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" + +[[package]] +name = "rayon" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf6960dc9a5b4ee8d3e4c5787b4a112a8818e0290a42ff664ad60692fdf2032" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "sysinfo" +version = "0.1.0" +dependencies = [ + "sysinfo 0.15.3", +] + +[[package]] +name = "sysinfo" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67330cbee3b2a819e3365a773f05e884a136603687f812bf24db5b6c3d76b696" +dependencies = [ + "cfg-if", + "doc-comment", + "libc", + "ntapi", + "once_cell", + "rayon", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/__linux/sysinfo/Cargo.toml b/__linux/sysinfo/Cargo.toml new file mode 100644 index 0000000..eb2b9df --- /dev/null +++ b/__linux/sysinfo/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "sysinfo" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +sysinfo = "0.15" + + diff --git a/__linux/sysinfo/src/main.rs b/__linux/sysinfo/src/main.rs new file mode 100644 index 0000000..e0dbe72 --- /dev/null +++ b/__linux/sysinfo/src/main.rs @@ -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()); + } +}