feat: 🎸 Uptime

This commit is contained in:
Atsukoro1 2022-12-01 11:34:34 +01:00
parent d27ab9a917
commit e0a139151f
3 changed files with 18 additions and 2 deletions

View file

@ -1,5 +1,5 @@
mod system;
fn main() {
println!("{}", system::specs::get_ram_used())
println!("{}", system::host::get_uptime())
}

View file

@ -57,4 +57,21 @@ pub fn get_distro() -> String {
});
distro.to_string()
}
#[cfg(target_os = "linux")]
pub fn get_uptime() -> String {
let mut temp_buf: String = String::new();
let mut file = File::open("/proc/uptime").unwrap();
file.read_to_string(&mut temp_buf).unwrap();
let uptime: u128 = temp_buf.split(".").collect::<Vec<&str>>()[0].parse().unwrap();
let days = uptime / 86400;
let hours = (uptime % 86400) / 3600;
let minutes = (uptime % 3600) / 60;
let seconds = uptime % 60;
format!("{}d {}h {}m {}s", days, hours, minutes, seconds)
}

View file

@ -1,6 +1,5 @@
use std::fs::File;
use std::io::Read;
use std::ops::Add;
use std::rc::Rc;
#[cfg(target_os = "linux")]