mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-08-28 19:47:54 +08:00
fix: 获取磁盘空间时筛选 SSD/HDD 并根据 name 去重,防止重复计算 (#563)
This commit is contained in:
@@ -11,12 +11,13 @@ use axum::{Extension, Router};
|
|||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use futures::stream::{SplitSink, SplitStream};
|
use futures::stream::{SplitSink, SplitStream};
|
||||||
use futures::{SinkExt, StreamExt, future};
|
use futures::{SinkExt, StreamExt, future};
|
||||||
|
use itertools::Itertools;
|
||||||
pub use log_helper::{LogHelper, MAX_HISTORY_LOGS};
|
pub use log_helper::{LogHelper, MAX_HISTORY_LOGS};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sysinfo::{
|
use sysinfo::{
|
||||||
CpuRefreshKind, DiskRefreshKind, Disks, MemoryRefreshKind, Pid, ProcessRefreshKind, ProcessesToUpdate, System,
|
CpuRefreshKind, DiskKind, DiskRefreshKind, Disks, MemoryRefreshKind, Pid, ProcessRefreshKind, ProcessesToUpdate,
|
||||||
get_current_pid,
|
System, get_current_pid,
|
||||||
};
|
};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::{pin, select};
|
use tokio::{pin, select};
|
||||||
@@ -245,14 +246,23 @@ impl WebSocketHandler {
|
|||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
let (available, total) = disks
|
||||||
|
.iter()
|
||||||
|
.filter(|d| !matches!(d.kind(), DiskKind::Unknown(_)))
|
||||||
|
.unique_by(|d| d.name())
|
||||||
|
.fold((0, 0), |(mut available, mut total), d| {
|
||||||
|
available += d.available_space();
|
||||||
|
total += d.total_space();
|
||||||
|
(available, total)
|
||||||
|
});
|
||||||
let sys_info = SysInfo {
|
let sys_info = SysInfo {
|
||||||
total_memory: system.total_memory(),
|
total_memory: system.total_memory(),
|
||||||
used_memory: system.used_memory(),
|
used_memory: system.used_memory(),
|
||||||
process_memory: process.memory(),
|
process_memory: process.memory(),
|
||||||
used_cpu: system.global_cpu_usage(),
|
used_cpu: system.global_cpu_usage(),
|
||||||
process_cpu: process.cpu_usage() / system.cpus().len() as f32,
|
process_cpu: process.cpu_usage() / system.cpus().len() as f32,
|
||||||
total_disk: disks.iter().map(|d| d.total_space()).sum(),
|
total_disk: total,
|
||||||
available_disk: disks.iter().map(|d| d.available_space()).sum(),
|
available_disk: available,
|
||||||
};
|
};
|
||||||
if tx.blocking_send(sys_info).is_err() {
|
if tx.blocking_send(sys_info).is_err() {
|
||||||
break;
|
break;
|
||||||
@@ -316,6 +326,6 @@ impl SysInfoExt for System {
|
|||||||
|
|
||||||
impl SysInfoExt for Disks {
|
impl SysInfoExt for Disks {
|
||||||
fn refresh_needed(&mut self, _self_pid: Pid) {
|
fn refresh_needed(&mut self, _self_pid: Pid) {
|
||||||
self.refresh_specifics(false, DiskRefreshKind::nothing().with_storage());
|
self.refresh_specifics(true, DiskRefreshKind::nothing().with_storage().with_kind());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user