From e0a139151f68be45788b615499fb16d0ddf213c7 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Thu, 1 Dec 2022 11:34:34 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Uptime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 2 +- src/system/host.rs | 17 +++++++++++++++++ src/system/specs.rs | 1 - 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4935410..5c385f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ mod system; fn main() { - println!("{}", system::specs::get_ram_used()) + println!("{}", system::host::get_uptime()) } diff --git a/src/system/host.rs b/src/system/host.rs index 518f52e..c6f0f6c 100644 --- a/src/system/host.rs +++ b/src/system/host.rs @@ -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::>()[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) } \ No newline at end of file diff --git a/src/system/specs.rs b/src/system/specs.rs index 6e44926..145235a 100644 --- a/src/system/specs.rs +++ b/src/system/specs.rs @@ -1,6 +1,5 @@ use std::fs::File; use std::io::Read; -use std::ops::Add; use std::rc::Rc; #[cfg(target_os = "linux")]