"##
))
}
async fn resources(State(_state): State>) -> Html {
let mut sys = System::new_all();
sys.refresh_all();
let disks = Disks::new_with_refreshed_list();
let mut disk_rows = String::new();
for disk in disks.list() {
let total = disk.total_space();
let available = disk.available_space();
let used = total - available;
let percent = if total > 0 {
(used as f64 / total as f64) * 100.0
} else {
0.0
};
disk_rows.push_str(&format!(
r##"
{mount}
{used_gb:.1} GB
{total_gb:.1} GB
{percent:.1}%
"##,
mount = disk.mount_point().display(),
used_gb = used as f64 / 1_073_741_824.0,
total_gb = total as f64 / 1_073_741_824.0,
status = if percent > 90.0 {
"danger"
} else if percent > 70.0 {
"warning"
} else {
"success"
},
));
}
let networks = Networks::new_with_refreshed_list();
let mut net_rows = String::new();
for (name, data) in networks.list() {
net_rows.push_str(&format!(
r##"
{name}
{rx:.2} MB
{tx:.2} MB
"##,
rx = data.total_received() as f64 / 1_048_576.0,
tx = data.total_transmitted() as f64 / 1_048_576.0,
));
}
Html(format!(
r##"