mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-22 16:10:50 +00:00
* feat(monitor): 优化磁盘IO展示与系统分区告警 [4030] * fix(monitor): 修复磁盘监控评审问题 [4030] * fix(monitor): align Partitions bars with Memory; hide bare / label Label-above-bar for partition list; single-root `/` hides the label and centers the bar like Memory/CPU (unchanged). Multi-disk keeps top align + system alerts. Disk IO adds a spacer row to track usage labels. Review crops under .github/review/ for PR discussion (drop before merge OK). * fix(monitor): keep bare-/ align; multi-disk labels stay left Address Chris density feedback: keep the single root label hidden and vertically centered with Memory, and restore side-by-side labels for multiple disks. Remove the Disk I/O spacer and update the review crops. * chore(monitor): drop PR #4031 discussion review crops --------- Co-authored-by: wendeng.dong <wendeng.dong@sailuntire.com> Co-authored-by: 陈大猫 <16399091+binaricat@users.noreply.github.com>
70 lines
2.8 KiB
TypeScript
70 lines
2.8 KiB
TypeScript
// Product display order; descendants stay with their system mount group.
|
|
const SYSTEM_MOUNTS = ["/", "/boot", "/etc", "/usr", "/var", "/home", "/opt", "/srv", "/tmp"];
|
|
const mountNames = new Intl.Collator("en", { numeric: true });
|
|
|
|
function mountPriority(mountPoint: string): number {
|
|
const rank = SYSTEM_MOUNTS.findIndex(path =>
|
|
mountPoint === path || (path !== "/" && mountPoint.startsWith(`${path}/`)),
|
|
);
|
|
return rank < 0 ? SYSTEM_MOUNTS.length : rank;
|
|
}
|
|
|
|
export interface MonitorDiskRow {
|
|
mountPoint: string;
|
|
percent: number | null;
|
|
used?: number | null;
|
|
total?: number | null;
|
|
diskReadSpeed?: number | null;
|
|
diskWriteSpeed?: number | null;
|
|
}
|
|
|
|
export type MonitorDiskListRow =
|
|
| { kind: "disk"; disk: MonitorDiskRow; alert: boolean }
|
|
| { kind: "system"; count: number; expanded: boolean; alert: boolean };
|
|
|
|
export interface MonitorDiskListStats {
|
|
disks: readonly MonitorDiskRow[];
|
|
diskPercent?: number | null;
|
|
diskUsed?: number | null;
|
|
diskTotal?: number | null;
|
|
}
|
|
|
|
export function isMonitorSystemDisk(mountPoint: string): boolean {
|
|
const priority = mountPriority(mountPoint);
|
|
return priority > 0 && priority < SYSTEM_MOUNTS.length;
|
|
}
|
|
|
|
export function monitorSystemDiskAlert(disk: MonitorDiskRow): boolean {
|
|
return isMonitorSystemDisk(disk.mountPoint)
|
|
&& typeof disk.percent === "number" && Number.isFinite(disk.percent) && disk.percent > 80;
|
|
}
|
|
|
|
/** One layout drives both columns, including a matching slot for the group header. */
|
|
export function buildMonitorDiskListLayout(stats?: MonitorDiskListStats | null, manuallyExpanded = false) {
|
|
const disks = sortMonitorDisks(stats?.disks.length ? stats.disks : [{
|
|
mountPoint: "/", percent: stats?.diskPercent ?? null,
|
|
used: stats?.diskUsed ?? null, total: stats?.diskTotal ?? null,
|
|
}]);
|
|
const system = disks.filter(disk => isMonitorSystemDisk(disk.mountPoint));
|
|
const forcedExpanded = system.some(monitorSystemDiskAlert);
|
|
const expanded = forcedExpanded || manuallyExpanded;
|
|
const rows: MonitorDiskListRow[] = disks
|
|
.filter(disk => !isMonitorSystemDisk(disk.mountPoint))
|
|
.map(disk => ({ kind: "disk", disk, alert: false }));
|
|
if (system.length) {
|
|
rows.push({ kind: "system", count: system.length, expanded, alert: forcedExpanded });
|
|
if (expanded) rows.push(...system.map(disk => ({ kind: "disk" as const, disk, alert: monitorSystemDiskAlert(disk) })));
|
|
}
|
|
return { rows, expanded, forcedExpanded };
|
|
}
|
|
|
|
export type MonitorDiskListLayout = ReturnType<typeof buildMonitorDiskListLayout>;
|
|
|
|
/** Sort a copy so capacity cards and other consumers retain the reported order. */
|
|
export function sortMonitorDisks<T extends { mountPoint: string }>(disks: readonly T[]): T[] {
|
|
return [...disks].sort((a, b) =>
|
|
mountPriority(a.mountPoint) - mountPriority(b.mountPoint)
|
|
|| mountNames.compare(a.mountPoint, b.mountPoint),
|
|
);
|
|
}
|