fix: report actual memory without cache
This commit is contained in:
@@ -380,16 +380,29 @@ async function collectSystemStatus(): Promise<SystemStatusSnapshot> {
|
||||
errors.push({ source: "proc.stat", error: error instanceof Error ? error.message : String(error) });
|
||||
}
|
||||
|
||||
let memory: Record<string, JsonValue> = { totalBytes: 0, usedBytes: 0, availableBytes: 0, percent: 0 };
|
||||
let memory: Record<string, JsonValue> = { totalBytes: 0, usedBytes: 0, availableBytes: 0, cacheBytes: 0, percent: 0, mode: "actual_without_cache" };
|
||||
try {
|
||||
const mem = readMemInfo();
|
||||
const totalBytes = mem.MemTotal ?? 0;
|
||||
const availableBytes = mem.MemAvailable ?? mem.MemFree ?? 0;
|
||||
const usedBytes = Math.max(0, totalBytes - availableBytes);
|
||||
const freeBytes = mem.MemFree ?? 0;
|
||||
const buffersBytes = mem.Buffers ?? 0;
|
||||
const cachedBytes = mem.Cached ?? 0;
|
||||
const reclaimableBytes = mem.SReclaimable ?? 0;
|
||||
const shmemBytes = mem.Shmem ?? 0;
|
||||
const cacheBytes = Math.max(0, buffersBytes + cachedBytes + reclaimableBytes - shmemBytes);
|
||||
const usedBytes = Math.max(0, totalBytes - freeBytes - cacheBytes);
|
||||
const availableBytes = mem.MemAvailable ?? Math.max(0, freeBytes + cacheBytes);
|
||||
memory = {
|
||||
mode: "actual_without_cache",
|
||||
totalBytes,
|
||||
usedBytes,
|
||||
availableBytes,
|
||||
freeBytes,
|
||||
cacheBytes,
|
||||
buffersBytes,
|
||||
cachedBytes,
|
||||
reclaimableBytes,
|
||||
shmemBytes,
|
||||
percent: totalBytes > 0 ? clampPercent((usedBytes / totalBytes) * 100) : 0,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user