From e92a60815196256049bf5ba237563df0c836d87a Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu@web.de> Date: Fri, 1 Mar 2019 18:48:36 +0100 Subject: [PATCH] Initial commit --- Cargo.lock | 4 ++++ Cargo.toml | 10 ++++++++++ src/main.rs | 15 +++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..3af13d8 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "sysinfo" +version = "0.1.0" + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a4bc0b5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "sysinfo" +version = "0.1.0" +authors = ["FliegendeWurst <2012gdwu@web.de>"] +edition = "2018" + +[profile.release] +panic = 'abort' + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..86babe5 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,15 @@ +use std::fs; + +fn main() { + let load = fs::read_to_string("/proc/loadavg").unwrap().split(' ').nth(0).unwrap().parse::().unwrap(); + let num_cpus = fs::read_dir("/sys/devices/system/cpu").unwrap() + .map(|x| x.unwrap().file_name().into_string().unwrap()) + .filter(|x| x.starts_with("cpu") && x.chars().nth(3).unwrap().is_numeric()) + .count() as f64; + let temp = fs::read_to_string("/sys/class/hwmon/hwmon0/temp1_input").unwrap().trim().parse::().unwrap() / 1000.0; + let meminfo = fs::read_to_string("/proc/meminfo").unwrap(); + let mut meminfo = meminfo.split('\n'); + let total = meminfo.next().unwrap().split_whitespace().nth(1).unwrap().parse::().unwrap() / 1_000; + let available = meminfo.nth(1).unwrap().split_whitespace().nth(1).unwrap().parse::().unwrap() / 1_000; + println!("{:.1}% {:.1}°C {}/{}MB", load / num_cpus * 100.0, temp, available, total); +}