mirror of
https://github.com/FliegendeWurst/sysinfo.git
synced 2024-11-27 16:15:53 +00:00
Initial commit
This commit is contained in:
commit
e92a608151
4
Cargo.lock
generated
Normal file
4
Cargo.lock
generated
Normal file
@ -0,0 +1,4 @@
|
||||
[[package]]
|
||||
name = "sysinfo"
|
||||
version = "0.1.0"
|
||||
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "sysinfo"
|
||||
version = "0.1.0"
|
||||
authors = ["FliegendeWurst <2012gdwu@web.de>"]
|
||||
edition = "2018"
|
||||
|
||||
[profile.release]
|
||||
panic = 'abort'
|
||||
|
||||
[dependencies]
|
15
src/main.rs
Normal file
15
src/main.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let load = fs::read_to_string("/proc/loadavg").unwrap().split(' ').nth(0).unwrap().parse::<f64>().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::<f64>().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::<u64>().unwrap() / 1_000;
|
||||
let available = meminfo.nth(1).unwrap().split_whitespace().nth(1).unwrap().parse::<u64>().unwrap() / 1_000;
|
||||
println!("{:.1}% {:.1}°C {}/{}MB", load / num_cpus * 100.0, temp, available, total);
|
||||
}
|
Loading…
Reference in New Issue
Block a user