mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-16 12:01:13 +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>
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
export const MONITOR_COLUMNS = [
|
|
{ key: "host", width: 220, min: 160 },
|
|
{ key: "latency", width: 90, min: 80 },
|
|
{ key: "tags", width: 150, min: 90 },
|
|
{ key: "notes", width: 180, min: 110 },
|
|
{ key: "cpu", width: 120, min: 120 },
|
|
{ key: "memory", width: 120, min: 120 },
|
|
{ key: "disks", width: 240, min: 220 },
|
|
{ key: "diskIo", width: 230, min: 220 },
|
|
{ key: "network", width: 150, min: 140 },
|
|
{ key: "updated", width: 110, min: 95 },
|
|
{ key: "status", width: 100, min: 90 },
|
|
{ key: "terminal", width: 56, min: 56 },
|
|
] as const;
|
|
export type MonitorColumn = (typeof MONITOR_COLUMNS)[number]["key"];
|
|
export type MonitorColumnWidths = Record<MonitorColumn, number>;
|
|
export const MONITOR_CARD_HEIGHT = 368;
|
|
|
|
export function clampMonitorColumnWidth(
|
|
key: MonitorColumn,
|
|
width: number,
|
|
): number {
|
|
const column = MONITOR_COLUMNS.find((column) => column.key === key)!;
|
|
return Number.isFinite(width)
|
|
? Math.round(
|
|
Math.max(column.min, Math.min(key === "terminal" ? 200 : 640, width)),
|
|
)
|
|
: column.width;
|
|
}
|
|
export function normalizeMonitorColumnWidths(
|
|
value: unknown,
|
|
): MonitorColumnWidths {
|
|
const stored =
|
|
value && typeof value === "object"
|
|
? (value as Record<string, unknown>)
|
|
: {};
|
|
return Object.fromEntries(
|
|
MONITOR_COLUMNS.map((column) => [
|
|
column.key,
|
|
clampMonitorColumnWidth(
|
|
column.key,
|
|
typeof stored[column.key] === "number"
|
|
? (stored[column.key] as number)
|
|
: column.width,
|
|
),
|
|
]),
|
|
) as MonitorColumnWidths;
|
|
}
|
|
export function monitorGridColumns(width: number, count: number): number {
|
|
return Math.max(
|
|
1,
|
|
Math.min(count, Math.floor((Math.max(0, width) + 16) / 296)),
|
|
);
|
|
}
|
|
|
|
/** Only optional columns can be hidden, including when restoring old or corrupt settings. */
|
|
export function normalizeMonitorHiddenColumns(value: unknown): MonitorColumn[] {
|
|
return MONITOR_COLUMNS.filter(
|
|
({ key }) =>
|
|
key !== "host" &&
|
|
key !== "terminal" &&
|
|
Array.isArray(value) &&
|
|
value.includes(key),
|
|
).map(({ key }) => key);
|
|
}
|