From e0b8b15849301da3d3d33d467f43f69cb7ed5d71 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 27 May 2024 17:53:41 +0100 Subject: [PATCH] Added RAM usage bars --- src/main.rs | 24 ++++++++++++++++-------- templates/index.html.tera | 6 ++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 81ae0ef..139b128 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,10 +35,14 @@ struct DiskInfo { #[derive(Serialize, Debug)] struct RamInfo { - total_memory: String, - used_memory: String, - total_swap: String, - used_swap: String, + total_memory: u64, + used_memory: u64, + total_swap: u64, + used_swap: u64, + total_memory_pretty: String, + used_memory_pretty: String, + total_swap_pretty: String, + used_swap_pretty: String, } #[derive(Serialize, Debug)] @@ -118,10 +122,14 @@ fn get_system_info(network_if_names: &Vec) -> SysInfo { disks: disks_context, components: components_context, ram: RamInfo { - total_memory: Byte::from(sys.total_memory()).to_string(), - used_memory: Byte::from(sys.used_memory()).to_string(), - total_swap: Byte::from(sys.total_swap()).to_string(), - used_swap: Byte::from(sys.used_swap()).to_string(), + total_memory: sys.total_memory(), + used_memory: sys.used_memory(), + total_swap: sys.total_swap(), + used_swap: sys.used_swap(), + total_memory_pretty: Byte::from(sys.total_memory()).to_string(), + used_memory_pretty: Byte::from(sys.used_memory()).to_string(), + total_swap_pretty: Byte::from(sys.total_swap()).to_string(), + used_swap_pretty: Byte::from(sys.used_swap()).to_string(), }, network_ifs: network_ifs, network_ifs_errored: network_ifs_errored, diff --git a/templates/index.html.tera b/templates/index.html.tera index ae0e4b7..14ae5e7 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -79,8 +79,10 @@

RAM

-

{{ system.ram.used_memory }} of {{ system.ram.total_memory }} RAM current in use

-

{{ system.ram.used_swap }} of {{ system.ram.total_swap }} swap currently in use

+

{{ system.ram.used_memory_pretty }} of {{ system.ram.total_memory_pretty }} RAM current in use

+ +

{{ system.ram.used_swap_pretty }} of {{ system.ram.total_swap_pretty }} swap currently in use

+

Network Interfaces