start working on mem
This commit is contained in:
parent
719d0d10be
commit
7ecb831db3
|
@ -10,3 +10,4 @@ dotenv-parser = "0.1.3"
|
|||
regex = "1.7.1"
|
||||
serde = {version = "1.0.154", features = ["derive"]}
|
||||
serde_json = "1.0.94"
|
||||
time-hms = "0.3.0"
|
||||
|
|
50
src/lib.rs
50
src/lib.rs
|
@ -1,29 +1,69 @@
|
|||
use std::fs::read_to_string;
|
||||
use dotenv_parser::parse_dotenv;
|
||||
use std::{fs::read_to_string, collections::HashMap};
|
||||
|
||||
pub fn get_os() -> String {
|
||||
let os_release = read_to_string("/etc/os-release").unwrap();
|
||||
let parsed = parse_dotenv(&os_release).unwrap();
|
||||
parsed.get("PRETTY_NAME").unwrap().clone().trim().to_string()
|
||||
parsed
|
||||
.get("PRETTY_NAME")
|
||||
.unwrap()
|
||||
.clone()
|
||||
.trim()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub fn get_cpu() {
|
||||
let binding = std::process::Command::new("lscpu").output().expect("lscpu failed");
|
||||
let binding = std::process::Command::new("lscpu")
|
||||
.output()
|
||||
.expect("lscpu failed");
|
||||
let lscpu = String::from_utf8_lossy(&binding.stdout);
|
||||
|
||||
println!("{}", &lscpu)
|
||||
}
|
||||
|
||||
pub fn get_arch() -> String {
|
||||
let binding = std::process::Command::new("uname").arg("-m").output().expect("uname failed");
|
||||
let binding = std::process::Command::new("uname")
|
||||
.arg("-m")
|
||||
.output()
|
||||
.expect("uname failed");
|
||||
let arch = String::from_utf8_lossy(&binding.stdout);
|
||||
|
||||
arch.to_string().trim().to_string()
|
||||
}
|
||||
|
||||
pub fn get_kernel_ver() -> String {
|
||||
let binding = std::process::Command::new("uname").arg("-r").output().expect("uname failed");
|
||||
let binding = std::process::Command::new("uname")
|
||||
.arg("-r")
|
||||
.output()
|
||||
.expect("uname failed");
|
||||
let ver = String::from_utf8_lossy(&binding.stdout);
|
||||
|
||||
ver.to_string().trim().to_string()
|
||||
}
|
||||
|
||||
pub fn get_uptime() -> time_hms::TimeHms {
|
||||
time_hms::TimeHms::new(
|
||||
read_to_string("/proc/uptime")
|
||||
.expect("couldn't read uptime file")
|
||||
.split(' ')
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.split('.')
|
||||
.collect::<Vec<&str>>()[0]
|
||||
.parse()
|
||||
.expect("couldnt parse number from uptime str"),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_ram() {
|
||||
let meminfo = read_to_string("/proc/meminfo").expect("couldnt read meminfo file");
|
||||
|
||||
let mut parsed: HashMap<String, String> = HashMap::new();
|
||||
|
||||
for line in meminfo.lines() {
|
||||
let mut l = line.split(": ").collect::<Vec<&str>>();
|
||||
let name = l.drain(0..1).collect::<Vec<&str>>()[0];
|
||||
let li = l.join(": ");
|
||||
parsed.insert(name.to_string(), li.trim().to_string());
|
||||
}
|
||||
println!("{:?}", parsed.get("MemAvailable").unwrap())
|
||||
}
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -3,6 +3,15 @@ fn main() {
|
|||
let os = get_os();
|
||||
let arch = get_arch();
|
||||
let kernel = get_kernel_ver();
|
||||
let uptime = get_uptime();
|
||||
let ram = get_ram();
|
||||
|
||||
println!("OS Name: {os}\nArchitecture: {arch}\nKernel Version: {kernel}");
|
||||
// ram
|
||||
// storage
|
||||
// cpu name/usage
|
||||
// gpu name/usage (not sure, might need external packages)
|
||||
// packages/package manager(s)
|
||||
// user/hostname
|
||||
|
||||
println!("OS Name: {os}\nArchitecture: {arch}\nKernel Version: {kernel}\nUptime: {}:{}:{}", uptime.h(), uptime.m(), uptime.s());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue