Skip to content
Merged
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions src/system_information/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Disk {
pub mount_point: String,
pub total_space: u64,
pub available_space: u64,
pub usage_percent: f64,
}

impl Disk {
Expand All @@ -21,19 +22,41 @@ impl Disk {

impl From<&sysinfo::Disk> for Disk {
fn from(sysinfo_disk: &sysinfo::Disk) -> Self {
let total_space = sysinfo_disk.total_space();
Comment thread
sbernauer marked this conversation as resolved.
let available_space = sysinfo_disk.available_space();
let usage_percent = if total_space > 0 {
(total_space - available_space) as f64 / total_space as f64 * 100.0
} else {
0.0
};

let disk = Disk {
name: sysinfo_disk.name().to_string_lossy().into_owned(),
mount_point: sysinfo_disk.mount_point().to_string_lossy().into_owned(),
total_space: sysinfo_disk.total_space(),
available_space: sysinfo_disk.available_space(),
total_space,
available_space,
usage_percent,
};
tracing::info!(
disk.mount_point,
disk.name,
disk.space.total = disk.total_space,
disk.space.available = disk.available_space,
"found disk"
);

if usage_percent >= 85.0 {
tracing::warn!(
disk.mount_point,
disk.name,
disk.space.total = disk.total_space,
disk.space.available = disk.available_space,
disk.space.usage_percent = format!("{:.1}%", disk.usage_percent),
"disk usage high"
);
} else {
tracing::info!(
disk.mount_point,
disk.name,
disk.space.total = disk.total_space,
disk.space.available = disk.available_space,
disk.space.usage_percent = format!("{:.1}%", disk.usage_percent),
"found disk"
);
}
disk
}
}
Loading