[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
76
components/terminal/serverStatsFormat.ts
Normal file
76
components/terminal/serverStatsFormat.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import {
|
||||
aggregateMountedDiskUsage,
|
||||
type MountedDiskUsage,
|
||||
} from "../../domain/systemDiskUsage";
|
||||
|
||||
interface TerminalDiskStats {
|
||||
diskUsed: number | null;
|
||||
diskTotal: number | null;
|
||||
diskPercent: number | null;
|
||||
disks: readonly MountedDiskUsage[];
|
||||
}
|
||||
|
||||
export interface TerminalDiskSummary {
|
||||
used: number | null;
|
||||
total: number | null;
|
||||
percent: number | null;
|
||||
}
|
||||
|
||||
export function formatDiskCapacityGb(value: number): string {
|
||||
return Number(value.toFixed(2)).toString();
|
||||
}
|
||||
|
||||
/** Capacity units, ascending from the GiB the collectors report in. */
|
||||
const DISK_CAPACITY_UNITS = ["G", "T", "P"] as const;
|
||||
|
||||
/** Pick the largest unit that keeps a GiB value at or above 1. */
|
||||
export function resolveDiskCapacityUnit(valueGb: number): { unit: string; divisor: number } {
|
||||
let divisor = 1;
|
||||
let index = 0;
|
||||
while (
|
||||
Math.abs(valueGb) / divisor >= 1024
|
||||
&& index < DISK_CAPACITY_UNITS.length - 1
|
||||
) {
|
||||
divisor *= 1024;
|
||||
index += 1;
|
||||
}
|
||||
return { unit: DISK_CAPACITY_UNITS[index], divisor };
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a used/total pair, both reported in GiB.
|
||||
*
|
||||
* Each side is scaled independently so a mostly-empty multi-terabyte pool keeps
|
||||
* its used figure — `136.37G/6.93T` rather than the `0.13/6.93T` a total-driven
|
||||
* unit would produce, or the unreadable `136.37/7096.47G` of a fixed one. When
|
||||
* both land in the same unit the suffix is written once, keeping the familiar
|
||||
* `71.12/878.15G` shape for ordinary disks.
|
||||
*/
|
||||
export function formatDiskCapacityRange(usedGb: number, totalGb: number): string {
|
||||
const used = resolveDiskCapacityUnit(usedGb);
|
||||
const total = resolveDiskCapacityUnit(totalGb);
|
||||
const usedText = formatDiskCapacityGb(usedGb / used.divisor);
|
||||
const totalText = formatDiskCapacityGb(totalGb / total.divisor);
|
||||
return used.unit === total.unit
|
||||
? `${usedText}/${totalText}${total.unit}`
|
||||
: `${usedText}${used.unit}/${totalText}${total.unit}`;
|
||||
}
|
||||
|
||||
export function resolveTerminalDiskSummary(
|
||||
stats: TerminalDiskStats,
|
||||
): TerminalDiskSummary {
|
||||
const mountedUsage = aggregateMountedDiskUsage(stats.disks);
|
||||
if (mountedUsage) {
|
||||
return {
|
||||
used: mountedUsage.used,
|
||||
total: mountedUsage.total,
|
||||
percent: Math.round(mountedUsage.percent),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
used: stats.diskUsed,
|
||||
total: stats.diskTotal,
|
||||
percent: stats.diskPercent,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user