diff options
Diffstat (limited to 'src/app/data_harvester/mem.rs')
-rw-r--r-- | src/app/data_harvester/mem.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/app/data_harvester/mem.rs b/src/app/data_harvester/mem.rs new file mode 100644 index 00000000..4bd3a0db --- /dev/null +++ b/src/app/data_harvester/mem.rs @@ -0,0 +1,35 @@ +use heim::units::information; + +#[derive(Debug, Clone)] +pub struct MemHarvest { + pub mem_total_in_mb: u64, + pub mem_used_in_mb: u64, +} + +impl Default for MemHarvest { + fn default() -> Self { + MemHarvest { + mem_total_in_mb: 0, + mem_used_in_mb: 0, + } + } +} + +pub async fn get_mem_data_list() -> crate::utils::error::Result<MemHarvest> { + let memory = heim::memory::memory().await?; + + Ok(MemHarvest { + mem_total_in_mb: memory.total().get::<information::megabyte>(), + mem_used_in_mb: memory.total().get::<information::megabyte>() + - memory.available().get::<information::megabyte>(), + }) +} + +pub async fn get_swap_data_list() -> crate::utils::error::Result<MemHarvest> { + let memory = heim::memory::swap().await?; + + Ok(MemHarvest { + mem_total_in_mb: memory.total().get::<information::megabyte>(), + mem_used_in_mb: memory.used().get::<information::megabyte>(), + }) +} |