fix: use total-available for mem_used, aggregate real filesystems for disk
Made-with: Cursor
This commit is contained in:
@@ -23,17 +23,20 @@ async function collect() {
|
||||
? r2(load.value.currentLoad)
|
||||
: null;
|
||||
|
||||
// 内存(bytes → KB)
|
||||
// 内存(bytes → KB);用 total - available 反映真实占用,与 free -h 一致
|
||||
const memVal = mem.status === 'fulfilled' ? mem.value : {};
|
||||
const mem_total = toKB(memVal.total);
|
||||
const mem_used = toKB(memVal.used);
|
||||
const mem_used = toKB((memVal.total || 0) - (memVal.available || 0));
|
||||
|
||||
// 磁盘:取挂载根目录 "/" 或第一个条目
|
||||
// 磁盘:聚合所有真实挂载点,排除虚拟文件系统
|
||||
const VIRTUAL_FS = new Set(['tmpfs', 'devtmpfs', 'overlay', 'squashfs', 'ramfs', 'sysfs', 'proc']);
|
||||
let disk_total = null, disk_used = null;
|
||||
if (fsArr.status === 'fulfilled' && fsArr.value.length > 0) {
|
||||
const root = fsArr.value.find(f => f.mount === '/') || fsArr.value[0];
|
||||
disk_total = toKB(root.size);
|
||||
disk_used = toKB(root.used);
|
||||
const realFs = fsArr.value.filter(f => f.size > 0 && !VIRTUAL_FS.has(f.type));
|
||||
if (realFs.length > 0) {
|
||||
disk_total = toKB(realFs.reduce((s, f) => s + f.size, 0));
|
||||
disk_used = toKB(realFs.reduce((s, f) => s + f.used, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// 温度
|
||||
|
||||
Reference in New Issue
Block a user