Fix disk available space display issue

- Parse available space from df output instead of showing total
- Add availableHuman field to disk metrics response
- Update frontend to display actual available space

Fixes #313
This commit is contained in:
ZacharyZcR
2025-10-02 14:07:58 +08:00
parent 1c8af91cc8
commit 1363e42c29
3 changed files with 13 additions and 5 deletions
+9 -1
View File
@@ -750,6 +750,7 @@ async function collectMetrics(host: SSHHostWithCredentials): Promise<{
let diskPercent: number | null = null; let diskPercent: number | null = null;
let usedHuman: string | null = null; let usedHuman: string | null = null;
let totalHuman: string | null = null; let totalHuman: string | null = null;
let availableHuman: string | null = null;
try { try {
const [diskOutHuman, diskOutBytes] = await Promise.all([ const [diskOutHuman, diskOutBytes] = await Promise.all([
execCommand(client, "df -h -P / | tail -n +2"), execCommand(client, "df -h -P / | tail -n +2"),
@@ -773,6 +774,7 @@ async function collectMetrics(host: SSHHostWithCredentials): Promise<{
if (humanParts.length >= 6 && bytesParts.length >= 6) { if (humanParts.length >= 6 && bytesParts.length >= 6) {
totalHuman = humanParts[1] || null; totalHuman = humanParts[1] || null;
usedHuman = humanParts[2] || null; usedHuman = humanParts[2] || null;
availableHuman = humanParts[3] || null; // Parse Available column from df output
const totalBytes = Number(bytesParts[1]); const totalBytes = Number(bytesParts[1]);
const usedBytes = Number(bytesParts[2]); const usedBytes = Number(bytesParts[2]);
@@ -796,6 +798,7 @@ async function collectMetrics(host: SSHHostWithCredentials): Promise<{
diskPercent = null; diskPercent = null;
usedHuman = null; usedHuman = null;
totalHuman = null; totalHuman = null;
availableHuman = null;
} }
const result = { const result = {
@@ -805,7 +808,12 @@ async function collectMetrics(host: SSHHostWithCredentials): Promise<{
usedGiB: usedGiB ? toFixedNum(usedGiB, 2) : null, usedGiB: usedGiB ? toFixedNum(usedGiB, 2) : null,
totalGiB: totalGiB ? toFixedNum(totalGiB, 2) : null, totalGiB: totalGiB ? toFixedNum(totalGiB, 2) : null,
}, },
disk: { percent: toFixedNum(diskPercent, 0), usedHuman, totalHuman }, disk: {
percent: toFixedNum(diskPercent, 0),
usedHuman,
totalHuman,
availableHuman, // Include available space in response
},
}; };
metricsCache.set(host.id, result); metricsCache.set(host.id, result);
+3 -4
View File
@@ -434,10 +434,9 @@ export function Server({
<div className="text-xs text-gray-500"> <div className="text-xs text-gray-500">
{(() => { {(() => {
const used = metrics?.disk?.usedHuman; const available = metrics?.disk?.availableHuman;
const total = metrics?.disk?.totalHuman; return available
return used && total ? `Available: ${available}`
? `Available: ${total}`
: "Available: N/A"; : "Available: N/A";
})()} })()}
</div> </div>
+1
View File
@@ -51,6 +51,7 @@ interface DiskMetrics {
percent: number | null; percent: number | null;
usedHuman: string | null; usedHuman: string | null;
totalHuman: string | null; totalHuman: string | null;
availableHuman?: string | null; // Available disk space from df output
} }
export type ServerMetrics = { export type ServerMetrics = {