From ef99e67507e9d5b8b588fa0a8488e2ea546a321f Mon Sep 17 00:00:00 2001 From: Hamed Date: Thu, 3 Dec 2026 04:19:48 +0330 Subject: [PATCH] feat(nodes): add fleet monitoring and implement the Penpot layout (#7342) Expose sampled CPU topology, absolute RAM, TCP/UDP counts, load averages and network throughput through the existing heartbeat and descendant contracts, preserving measured zero versus unavailable values. Add an explicit nullable telemetry migration and freshness/availability checks. Provide read-only All nodes and Master rows with deduplicated host/client totals, grouped SQL aggregation and reporting coverage. Preserve known descendants during parent outages and prefer the freshest valid observation of shared GUIDs. Keep the ordinary heartbeat broadcast free of fleet-wide totals. Implement the approved compact Penpot-inspired Nodes layout, responsive stacked details, status diagnostics and existing remote actions. Preserve cached rows, search and controls on overview refresh failures. By maintainer decision, hide both system rows when no remote nodes are registered. Final review of 44ed4579856020f7bfebb42fc522de4d6c2b8ca4: no outstanding HIGH or MEDIUM findings. CI and Docs CI passed (13 jobs; 2342 frontend tests in 269 files), including Go/race and mixed-version node E2E. Feature-specific PostgreSQL regression execution was not independently verified in the selected CI logs. See https://github.com/MHSanaei/3x-ui/pull/7342#issuecomment-7363599190. Closes #7335 Closes #7336 Closes #7337 --- docs/content/docs/en/reference/api/nodes.mdx | 9 +- docs/public/openapi.json | 288 +++ frontend/public/openapi.json | 288 +++ frontend/src/api/queries/useNodesQuery.ts | 29 +- frontend/src/api/queryKeys.ts | 1 + frontend/src/generated/examples.ts | 73 + frontend/src/generated/schemas.ts | 220 +++ frontend/src/generated/types.ts | 47 + frontend/src/generated/zod.ts | 51 + frontend/src/pages/api-docs/endpoints.ts | 7 + frontend/src/pages/nodes/NodeList.css | 776 ++++++-- frontend/src/pages/nodes/NodeList.stories.tsx | 169 ++ frontend/src/pages/nodes/NodeList.tsx | 1632 +++++++++-------- frontend/src/pages/nodes/NodeNetworkSpeed.tsx | 72 +- frontend/src/pages/nodes/NodesPage.tsx | 118 +- frontend/src/pages/nodes/fleetTelemetry.ts | 103 ++ frontend/src/pages/nodes/fonts/LICENSE.txt | 93 + .../nodes/fonts/SourceSansPro-Bold.woff2 | Bin 0 -> 76860 bytes .../nodes/fonts/SourceSansPro-Regular.woff2 | Bin 0 -> 62636 bytes .../nodes/fonts/SourceSansPro-Semibold.woff2 | Bin 0 -> 77452 bytes frontend/src/schemas/node.ts | 7 + .../src/test/node-fleet-monitoring.test.tsx | 125 ++ frontend/src/test/node-list-a11y.test.tsx | 9 +- .../src/test/node-list-online-total.test.tsx | 18 +- frontend/src/test/node-list-rerender.test.tsx | 1 - frontend/src/test/node-list-rowkey.test.tsx | 1 - .../test/node-list-untrusted-i18n.test.tsx | 1 - .../test/node-metrics-availability.test.tsx | 141 +- .../src/test/node-overview-refresh.test.tsx | 47 + frontend/src/test/node-restart.test.tsx | 131 +- internal/database/db.go | 12 + internal/database/model/model.go | 16 +- internal/database/model/node_telemetry.go | 22 + .../database/node_telemetry_migration_test.go | 42 + internal/web/controller/api.go | 5 + internal/web/controller/node.go | 11 + internal/web/controller/server.go | 4 +- .../job/node_heartbeat_descendants_test.go | 65 +- internal/web/job/node_heartbeat_job.go | 14 +- internal/web/service/node.go | 196 +- internal/web/service/node_contract.go | 91 +- internal/web/service/node_fleet.go | 162 ++ internal/web/service/node_fleet_test.go | 343 ++++ internal/web/service/node_shared_guid_test.go | 4 +- internal/web/service/node_telemetry.go | 123 ++ internal/web/service/node_tree.go | 209 +-- internal/web/service/server.go | 13 +- internal/web/service/server_scope_test.go | 4 +- internal/web/translation/ar-EG.json | 37 +- internal/web/translation/en-US.json | 37 +- internal/web/translation/es-ES.json | 37 +- internal/web/translation/fa-IR.json | 37 +- internal/web/translation/id-ID.json | 37 +- internal/web/translation/ja-JP.json | 37 +- internal/web/translation/pt-BR.json | 37 +- internal/web/translation/ru-RU.json | 37 +- internal/web/translation/sk-SK.json | 37 +- internal/web/translation/tr-TR.json | 37 +- internal/web/translation/uk-UA.json | 37 +- internal/web/translation/vi-VN.json | 37 +- internal/web/translation/zh-CN.json | 37 +- internal/web/translation/zh-TW.json | 37 +- internal/web/web.go | 3 +- tools/openapigen/main.go | 4 + 64 files changed, 4710 insertions(+), 1608 deletions(-) create mode 100644 frontend/src/pages/nodes/NodeList.stories.tsx create mode 100644 frontend/src/pages/nodes/fleetTelemetry.ts create mode 100644 frontend/src/pages/nodes/fonts/LICENSE.txt create mode 100644 frontend/src/pages/nodes/fonts/SourceSansPro-Bold.woff2 create mode 100644 frontend/src/pages/nodes/fonts/SourceSansPro-Regular.woff2 create mode 100644 frontend/src/pages/nodes/fonts/SourceSansPro-Semibold.woff2 create mode 100644 frontend/src/test/node-fleet-monitoring.test.tsx create mode 100644 frontend/src/test/node-overview-refresh.test.tsx create mode 100644 internal/database/model/node_telemetry.go create mode 100644 internal/database/node_telemetry_migration_test.go create mode 100644 internal/web/service/node_fleet.go create mode 100644 internal/web/service/node_fleet_test.go create mode 100644 internal/web/service/node_telemetry.go diff --git a/docs/content/docs/en/reference/api/nodes.mdx b/docs/content/docs/en/reference/api/nodes.mdx index fb6e627e3..afc8cc506 100644 --- a/docs/content/docs/en/reference/api/nodes.mdx +++ b/docs/content/docs/en/reference/api/nodes.mdx @@ -11,6 +11,10 @@ _openapi: title: List every configured node with its connection details, health, and last heartbeat patch. url: '#list-every-configured-node-with-its-connection-details-health-and-last-heartbeat-patch' + - depth: 2 + title: Read the local panel, unique fleet client counts and sampled remote host + telemetry. + url: '#read-the-local-panel-unique-fleet-client-counts-and-sampled-remote-host-telemetry' - depth: 2 title: This panel's node-auth CA certificate (public, PEM) to paste into a node's mTLS trust setting. Lazily mints the CA and the master client @@ -99,6 +103,9 @@ _openapi: - content: List every configured node with its connection details, health, and last heartbeat patch. id: list-every-configured-node-with-its-connection-details-health-and-last-heartbeat-patch + - content: Read the local panel, unique fleet client counts and sampled remote + host telemetry. + id: read-the-local-panel-unique-fleet-client-counts-and-sampled-remote-host-telemetry - content: This panel's node-auth CA certificate (public, PEM) to paste into a node's mTLS trust setting. Lazily mints the CA and the master client cert on first call. Pair with setting tlsVerifyMode=mtls on the node. @@ -175,7 +182,7 @@ export default function Layout(props) { return ( <> {props.children} - + ); } \ No newline at end of file diff --git a/docs/public/openapi.json b/docs/public/openapi.json index 870ef99e3..6774178eb 100644 --- a/docs/public/openapi.json +++ b/docs/public/openapi.json @@ -4755,6 +4755,14 @@ "example": "online", "type": "string" }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, "tlsVerifyMode": { "enum": [ "verify", @@ -4916,6 +4924,43 @@ ], "type": "object" }, + "NodeFleetCounts": { + "properties": { + "activeCount": { + "example": 90, + "type": "integer" + }, + "clientCount": { + "example": 100, + "type": "integer" + }, + "depletedCount": { + "example": 2, + "type": "integer" + }, + "disabledCount": { + "example": 8, + "type": "integer" + }, + "inboundCount": { + "example": 8, + "type": "integer" + }, + "onlineCount": { + "example": 20, + "type": "integer" + } + }, + "required": [ + "activeCount", + "clientCount", + "depletedCount", + "disabledCount", + "inboundCount", + "onlineCount" + ], + "type": "object" + }, "NodeInboundTraffic": { "properties": { "down": { @@ -4938,6 +4983,40 @@ ], "type": "object" }, + "NodeMasterView": { + "properties": { + "counts": { + "$ref": "#/components/schemas/NodeFleetCounts" + }, + "panelVersion": { + "example": "v3.12.0", + "type": "string" + }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, + "xrayError": { + "type": "string" + }, + "xrayState": { + "example": "running", + "type": "string" + }, + "xrayVersion": { + "example": "26.1.1", + "type": "string" + } + }, + "required": [ + "counts" + ], + "type": "object" + }, "NodeMutationRequest": { "description": "NodeMutationRequest is the node write/probe contract. ApiToken is accepted\nonly as input. On update, nil means keep the stored token; replacement and\nclearing are explicit and mutually exclusive.", "properties": { @@ -5028,6 +5107,33 @@ ], "type": "object" }, + "NodeOverview": { + "properties": { + "fleet": { + "$ref": "#/components/schemas/NodeFleetCounts" + }, + "master": { + "$ref": "#/components/schemas/NodeMasterView" + }, + "nodes": { + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeView" + } + ], + "nullable": true + }, + "type": "array" + } + }, + "required": [ + "fleet", + "master", + "nodes" + ], + "type": "object" + }, "NodeSnapshotAttachment": { "properties": { "email": { @@ -5071,6 +5177,106 @@ ], "type": "object" }, + "NodeTelemetry": { + "description": "NodeTelemetry describes one host sample. Nil metrics were not measured.", + "properties": { + "cpuPct": { + "example": 12.5, + "nullable": true, + "type": "number" + }, + "load1": { + "example": 0.25, + "nullable": true, + "type": "number" + }, + "load15": { + "example": 0.12, + "nullable": true, + "type": "number" + }, + "load5": { + "example": 0.18, + "nullable": true, + "type": "number" + }, + "logicalCores": { + "example": 8, + "nullable": true, + "type": "integer" + }, + "memAvailableBytes": { + "example": 1073741824, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "memTotalBytes": { + "example": 4294967296, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "memUsedBytes": { + "example": 2147483648, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "netDown": { + "example": 2048, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "netUp": { + "example": 1024, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "physicalCores": { + "example": 4, + "nullable": true, + "type": "integer" + }, + "resourceScope": { + "example": "container", + "type": "string" + }, + "sampleAgeMillis": { + "example": 125, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "sampledAt": { + "example": 1700000000000, + "format": "int64", + "type": "integer" + }, + "tcpCount": { + "example": 75, + "nullable": true, + "type": "integer" + }, + "udpCount": { + "example": 12, + "nullable": true, + "type": "integer" + }, + "uptimeSecs": { + "example": 3600, + "format": "int64", + "nullable": true, + "type": "integer" + } + }, + "required": [ + "sampledAt" + ], + "type": "object" + }, "NodeTrafficSnapshotV1": { "description": "NodeTrafficSnapshotV1 carries complete counters every tick; only unchanged structure is omitted.", "properties": { @@ -5302,6 +5508,14 @@ "example": "online", "type": "string" }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, "tlsVerifyMode": { "example": "verify", "type": "string" @@ -6205,6 +6419,12 @@ "resourceScope": { "type": "string" }, + "sampleAgeMillis": { + "example": 125, + "format": "int64", + "nullable": true, + "type": "integer" + }, "swap": {}, "tcpCount": { "type": "integer" @@ -8270,6 +8490,7 @@ "panelVersion": "", "publicIP": null, "resourceScope": "", + "sampleAgeMillis": 125, "swap": null, "tcpCount": 0, "udpCount": 0, @@ -14490,6 +14711,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -14509,6 +14731,69 @@ } } }, + "/panel/api/nodes/overview": { + "get": { + "tags": [ + "Nodes" + ], + "summary": "Read the local panel, unique fleet client counts and sampled remote host telemetry.", + "operationId": "get_panel_api_nodes_overview", + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": { + "$ref": "#/components/schemas/NodeOverview" + } + } + }, + "example": { + "success": true, + "obj": { + "fleet": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, + "master": { + "counts": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, + "panelVersion": "v3.12.0", + "telemetry": null, + "xrayError": "", + "xrayState": "running", + "xrayVersion": "26.1.1" + }, + "nodes": [ + null + ] + } + } + } + } + } + } + } + }, "/panel/api/nodes/mtls/ca": { "post": { "tags": [ @@ -14696,6 +14981,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -14851,6 +15137,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -20654,6 +20941,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 870ef99e3..6774178eb 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -4755,6 +4755,14 @@ "example": "online", "type": "string" }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, "tlsVerifyMode": { "enum": [ "verify", @@ -4916,6 +4924,43 @@ ], "type": "object" }, + "NodeFleetCounts": { + "properties": { + "activeCount": { + "example": 90, + "type": "integer" + }, + "clientCount": { + "example": 100, + "type": "integer" + }, + "depletedCount": { + "example": 2, + "type": "integer" + }, + "disabledCount": { + "example": 8, + "type": "integer" + }, + "inboundCount": { + "example": 8, + "type": "integer" + }, + "onlineCount": { + "example": 20, + "type": "integer" + } + }, + "required": [ + "activeCount", + "clientCount", + "depletedCount", + "disabledCount", + "inboundCount", + "onlineCount" + ], + "type": "object" + }, "NodeInboundTraffic": { "properties": { "down": { @@ -4938,6 +4983,40 @@ ], "type": "object" }, + "NodeMasterView": { + "properties": { + "counts": { + "$ref": "#/components/schemas/NodeFleetCounts" + }, + "panelVersion": { + "example": "v3.12.0", + "type": "string" + }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, + "xrayError": { + "type": "string" + }, + "xrayState": { + "example": "running", + "type": "string" + }, + "xrayVersion": { + "example": "26.1.1", + "type": "string" + } + }, + "required": [ + "counts" + ], + "type": "object" + }, "NodeMutationRequest": { "description": "NodeMutationRequest is the node write/probe contract. ApiToken is accepted\nonly as input. On update, nil means keep the stored token; replacement and\nclearing are explicit and mutually exclusive.", "properties": { @@ -5028,6 +5107,33 @@ ], "type": "object" }, + "NodeOverview": { + "properties": { + "fleet": { + "$ref": "#/components/schemas/NodeFleetCounts" + }, + "master": { + "$ref": "#/components/schemas/NodeMasterView" + }, + "nodes": { + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeView" + } + ], + "nullable": true + }, + "type": "array" + } + }, + "required": [ + "fleet", + "master", + "nodes" + ], + "type": "object" + }, "NodeSnapshotAttachment": { "properties": { "email": { @@ -5071,6 +5177,106 @@ ], "type": "object" }, + "NodeTelemetry": { + "description": "NodeTelemetry describes one host sample. Nil metrics were not measured.", + "properties": { + "cpuPct": { + "example": 12.5, + "nullable": true, + "type": "number" + }, + "load1": { + "example": 0.25, + "nullable": true, + "type": "number" + }, + "load15": { + "example": 0.12, + "nullable": true, + "type": "number" + }, + "load5": { + "example": 0.18, + "nullable": true, + "type": "number" + }, + "logicalCores": { + "example": 8, + "nullable": true, + "type": "integer" + }, + "memAvailableBytes": { + "example": 1073741824, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "memTotalBytes": { + "example": 4294967296, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "memUsedBytes": { + "example": 2147483648, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "netDown": { + "example": 2048, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "netUp": { + "example": 1024, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "physicalCores": { + "example": 4, + "nullable": true, + "type": "integer" + }, + "resourceScope": { + "example": "container", + "type": "string" + }, + "sampleAgeMillis": { + "example": 125, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "sampledAt": { + "example": 1700000000000, + "format": "int64", + "type": "integer" + }, + "tcpCount": { + "example": 75, + "nullable": true, + "type": "integer" + }, + "udpCount": { + "example": 12, + "nullable": true, + "type": "integer" + }, + "uptimeSecs": { + "example": 3600, + "format": "int64", + "nullable": true, + "type": "integer" + } + }, + "required": [ + "sampledAt" + ], + "type": "object" + }, "NodeTrafficSnapshotV1": { "description": "NodeTrafficSnapshotV1 carries complete counters every tick; only unchanged structure is omitted.", "properties": { @@ -5302,6 +5508,14 @@ "example": "online", "type": "string" }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, "tlsVerifyMode": { "example": "verify", "type": "string" @@ -6205,6 +6419,12 @@ "resourceScope": { "type": "string" }, + "sampleAgeMillis": { + "example": 125, + "format": "int64", + "nullable": true, + "type": "integer" + }, "swap": {}, "tcpCount": { "type": "integer" @@ -8270,6 +8490,7 @@ "panelVersion": "", "publicIP": null, "resourceScope": "", + "sampleAgeMillis": 125, "swap": null, "tcpCount": 0, "udpCount": 0, @@ -14490,6 +14711,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -14509,6 +14731,69 @@ } } }, + "/panel/api/nodes/overview": { + "get": { + "tags": [ + "Nodes" + ], + "summary": "Read the local panel, unique fleet client counts and sampled remote host telemetry.", + "operationId": "get_panel_api_nodes_overview", + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "success": { + "type": "boolean" + }, + "msg": { + "type": "string" + }, + "obj": { + "$ref": "#/components/schemas/NodeOverview" + } + } + }, + "example": { + "success": true, + "obj": { + "fleet": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, + "master": { + "counts": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, + "panelVersion": "v3.12.0", + "telemetry": null, + "xrayError": "", + "xrayState": "running", + "xrayVersion": "26.1.1" + }, + "nodes": [ + null + ] + } + } + } + } + } + } + } + }, "/panel/api/nodes/mtls/ca": { "post": { "tags": [ @@ -14696,6 +14981,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -14851,6 +15137,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -20654,6 +20941,7 @@ "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ diff --git a/frontend/src/api/queries/useNodesQuery.ts b/frontend/src/api/queries/useNodesQuery.ts index 23d5db507..7273fb719 100644 --- a/frontend/src/api/queries/useNodesQuery.ts +++ b/frontend/src/api/queries/useNodesQuery.ts @@ -3,12 +3,39 @@ import { useMemo } from 'react'; import { HttpUtil } from '@/utils'; import { parseMsg } from '@/utils/zodValidate'; -import { NodeListSchema } from '@/schemas/node'; +import { NodeListSchema, NodeOverviewSchema } from '@/schemas/node'; import type { NodeRecord } from '@/schemas/node'; import { keys } from '@/api/queryKeys'; export type { NodeRecord }; +async function fetchNodeOverview() { + const msg = await HttpUtil.get('/panel/api/nodes/overview', undefined, { silent: true }); + if (!msg.success || msg.obj == null) throw new Error(msg.msg || 'Failed to fetch node overview'); + return NodeOverviewSchema.parse(msg.obj); +} + +const emptyNodes: NodeRecord[] = []; + +export function useNodeOverviewQuery() { + const query = useQuery({ + queryKey: keys.nodes.overview(), + queryFn: fetchNodeOverview, + refetchInterval: 5_000, + }); + return { + nodes: query.data?.nodes ?? emptyNodes, + master: query.data?.master, + fleet: query.data?.fleet, + nodesUpdatedAt: query.dataUpdatedAt, + loading: query.isFetching, + fetched: query.data !== undefined || query.isError, + fetchError: query.isLoadingError ? query.error.message : '', + refreshError: query.isRefetchError ? query.error.message : '', + refetch: query.refetch, + }; +} + export interface NodeTotals { total: number; online: number; diff --git a/frontend/src/api/queryKeys.ts b/frontend/src/api/queryKeys.ts index c03d796ad..e8448b04b 100644 --- a/frontend/src/api/queryKeys.ts +++ b/frontend/src/api/queryKeys.ts @@ -8,6 +8,7 @@ export const keys = { nodes: { root: () => ['nodes'] as const, list: () => ['nodes', 'list'] as const, + overview: () => ['nodes', 'overview'] as const, }, hosts: { root: () => ['hosts'] as const, diff --git a/frontend/src/generated/examples.ts b/frontend/src/generated/examples.ts index b8e09aa02..1a2cd19d9 100644 --- a/frontend/src/generated/examples.ts +++ b/frontend/src/generated/examples.ts @@ -1297,6 +1297,7 @@ export const EXAMPLES: Record = { "remark": "", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -1324,11 +1325,34 @@ export const EXAMPLES: Record = { "total": 10737418240, "up": 1048576 }, + "NodeFleetCounts": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, "NodeInboundTraffic": { "down": 0, "id": 1, "up": 0 }, + "NodeMasterView": { + "counts": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, + "panelVersion": "v3.12.0", + "telemetry": null, + "xrayError": "", + "xrayState": "running", + "xrayVersion": "26.1.1" + }, "NodeMutationRequest": { "address": "", "allowPrivateAddress": false, @@ -1349,6 +1373,34 @@ export const EXAMPLES: Record = { "scheme": "http", "tlsVerifyMode": "verify" }, + "NodeOverview": { + "fleet": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, + "master": { + "counts": { + "activeCount": 90, + "clientCount": 100, + "depletedCount": 2, + "disabledCount": 8, + "inboundCount": 8, + "onlineCount": 20 + }, + "panelVersion": "v3.12.0", + "telemetry": null, + "xrayError": "", + "xrayState": "running", + "xrayVersion": "26.1.1" + }, + "nodes": [ + null + ] + }, "NodeSnapshotAttachment": { "email": "user1", "inboundId": 1 @@ -1364,6 +1416,25 @@ export const EXAMPLES: Record = { null ] }, + "NodeTelemetry": { + "cpuPct": 12.5, + "load1": 0.25, + "load15": 0.12, + "load5": 0.18, + "logicalCores": 8, + "memAvailableBytes": 1073741824, + "memTotalBytes": 4294967296, + "memUsedBytes": 2147483648, + "netDown": 2048, + "netUp": 1024, + "physicalCores": 4, + "resourceScope": "container", + "sampleAgeMillis": 125, + "sampledAt": 1700000000000, + "tcpCount": 75, + "udpCount": 12, + "uptimeSecs": 3600 + }, "NodeTrafficSnapshotV1": { "activeInboundTree": {}, "clients": [ @@ -1439,6 +1510,7 @@ export const EXAMPLES: Record = { "remark": "Primary edge", "scheme": "https", "status": "online", + "telemetry": null, "tlsVerifyMode": "verify", "transitive": false, "unavailableMetrics": [ @@ -1674,6 +1746,7 @@ export const EXAMPLES: Record = { "panelVersion": "", "publicIP": null, "resourceScope": "", + "sampleAgeMillis": 125, "swap": null, "tcpCount": 0, "udpCount": 0, diff --git a/frontend/src/generated/schemas.ts b/frontend/src/generated/schemas.ts index 378fc8b16..2b7872427 100644 --- a/frontend/src/generated/schemas.ts +++ b/frontend/src/generated/schemas.ts @@ -4729,6 +4729,14 @@ export const SCHEMAS: Record = { "example": "online", "type": "string" }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, "tlsVerifyMode": { "enum": [ "verify", @@ -4890,6 +4898,43 @@ export const SCHEMAS: Record = { ], "type": "object" }, + "NodeFleetCounts": { + "properties": { + "activeCount": { + "example": 90, + "type": "integer" + }, + "clientCount": { + "example": 100, + "type": "integer" + }, + "depletedCount": { + "example": 2, + "type": "integer" + }, + "disabledCount": { + "example": 8, + "type": "integer" + }, + "inboundCount": { + "example": 8, + "type": "integer" + }, + "onlineCount": { + "example": 20, + "type": "integer" + } + }, + "required": [ + "activeCount", + "clientCount", + "depletedCount", + "disabledCount", + "inboundCount", + "onlineCount" + ], + "type": "object" + }, "NodeInboundTraffic": { "properties": { "down": { @@ -4912,6 +4957,40 @@ export const SCHEMAS: Record = { ], "type": "object" }, + "NodeMasterView": { + "properties": { + "counts": { + "$ref": "#/components/schemas/NodeFleetCounts" + }, + "panelVersion": { + "example": "v3.12.0", + "type": "string" + }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, + "xrayError": { + "type": "string" + }, + "xrayState": { + "example": "running", + "type": "string" + }, + "xrayVersion": { + "example": "26.1.1", + "type": "string" + } + }, + "required": [ + "counts" + ], + "type": "object" + }, "NodeMutationRequest": { "description": "NodeMutationRequest is the node write/probe contract. ApiToken is accepted\nonly as input. On update, nil means keep the stored token; replacement and\nclearing are explicit and mutually exclusive.", "properties": { @@ -5002,6 +5081,33 @@ export const SCHEMAS: Record = { ], "type": "object" }, + "NodeOverview": { + "properties": { + "fleet": { + "$ref": "#/components/schemas/NodeFleetCounts" + }, + "master": { + "$ref": "#/components/schemas/NodeMasterView" + }, + "nodes": { + "items": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeView" + } + ], + "nullable": true + }, + "type": "array" + } + }, + "required": [ + "fleet", + "master", + "nodes" + ], + "type": "object" + }, "NodeSnapshotAttachment": { "properties": { "email": { @@ -5045,6 +5151,106 @@ export const SCHEMAS: Record = { ], "type": "object" }, + "NodeTelemetry": { + "description": "NodeTelemetry describes one host sample. Nil metrics were not measured.", + "properties": { + "cpuPct": { + "example": 12.5, + "nullable": true, + "type": "number" + }, + "load1": { + "example": 0.25, + "nullable": true, + "type": "number" + }, + "load15": { + "example": 0.12, + "nullable": true, + "type": "number" + }, + "load5": { + "example": 0.18, + "nullable": true, + "type": "number" + }, + "logicalCores": { + "example": 8, + "nullable": true, + "type": "integer" + }, + "memAvailableBytes": { + "example": 1073741824, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "memTotalBytes": { + "example": 4294967296, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "memUsedBytes": { + "example": 2147483648, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "netDown": { + "example": 2048, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "netUp": { + "example": 1024, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "physicalCores": { + "example": 4, + "nullable": true, + "type": "integer" + }, + "resourceScope": { + "example": "container", + "type": "string" + }, + "sampleAgeMillis": { + "example": 125, + "format": "int64", + "nullable": true, + "type": "integer" + }, + "sampledAt": { + "example": 1700000000000, + "format": "int64", + "type": "integer" + }, + "tcpCount": { + "example": 75, + "nullable": true, + "type": "integer" + }, + "udpCount": { + "example": 12, + "nullable": true, + "type": "integer" + }, + "uptimeSecs": { + "example": 3600, + "format": "int64", + "nullable": true, + "type": "integer" + } + }, + "required": [ + "sampledAt" + ], + "type": "object" + }, "NodeTrafficSnapshotV1": { "description": "NodeTrafficSnapshotV1 carries complete counters every tick; only unchanged structure is omitted.", "properties": { @@ -5276,6 +5482,14 @@ export const SCHEMAS: Record = { "example": "online", "type": "string" }, + "telemetry": { + "allOf": [ + { + "$ref": "#/components/schemas/NodeTelemetry" + } + ], + "nullable": true + }, "tlsVerifyMode": { "example": "verify", "type": "string" @@ -6179,6 +6393,12 @@ export const SCHEMAS: Record = { "resourceScope": { "type": "string" }, + "sampleAgeMillis": { + "example": 125, + "format": "int64", + "nullable": true, + "type": "integer" + }, "swap": {}, "tcpCount": { "type": "integer" diff --git a/frontend/src/generated/types.ts b/frontend/src/generated/types.ts index 4d2bca454..e97cad010 100644 --- a/frontend/src/generated/types.ts +++ b/frontend/src/generated/types.ts @@ -1092,6 +1092,7 @@ export interface Node { remark: string; scheme: string; status: string; + telemetry?: NodeTelemetry | null; tlsVerifyMode: string; transitive?: boolean; unavailableMetrics?: string[]; @@ -1119,12 +1120,30 @@ export interface NodeClientTraffic { up: number; } +export interface NodeFleetCounts { + activeCount: number; + clientCount: number; + depletedCount: number; + disabledCount: number; + inboundCount: number; + onlineCount: number; +} + export interface NodeInboundTraffic { down: number; id: number; up: number; } +export interface NodeMasterView { + counts: NodeFleetCounts; + panelVersion?: string; + telemetry?: NodeTelemetry | null; + xrayError?: string; + xrayState?: string; + xrayVersion?: string; +} + export interface NodeMutationRequest { address: string; allowPrivateAddress: boolean; @@ -1144,6 +1163,12 @@ export interface NodeMutationRequest { tlsVerifyMode: string; } +export interface NodeOverview { + fleet: NodeFleetCounts; + master: NodeMasterView; + nodes: NodeView | null[]; +} + export interface NodeSnapshotAttachment { email: string; inboundId: number; @@ -1154,6 +1179,26 @@ export interface NodeSnapshotStructure { inbounds: Inbound | null[]; } +export interface NodeTelemetry { + cpuPct?: number | null; + load1?: number | null; + load15?: number | null; + load5?: number | null; + logicalCores?: number | null; + memAvailableBytes?: number | null; + memTotalBytes?: number | null; + memUsedBytes?: number | null; + netDown?: number | null; + netUp?: number | null; + physicalCores?: number | null; + resourceScope?: string; + sampleAgeMillis?: number | null; + sampledAt: number; + tcpCount?: number | null; + udpCount?: number | null; + uptimeSecs?: number | null; +} + export interface NodeTrafficSnapshotV1 { activeInboundTree: Record; clients: NodeClientTraffic[]; @@ -1203,6 +1248,7 @@ export interface NodeView { remark: string; scheme: string; status: string; + telemetry?: NodeTelemetry | null; tlsVerifyMode: string; transitive?: boolean; unavailableMetrics?: string[]; @@ -1411,6 +1457,7 @@ export interface Status { panelVersion: string; publicIP: unknown; resourceScope?: string; + sampleAgeMillis?: number | null; swap: unknown; tcpCount: number; udpCount: number; diff --git a/frontend/src/generated/zod.ts b/frontend/src/generated/zod.ts index de23c7e02..cab871448 100644 --- a/frontend/src/generated/zod.ts +++ b/frontend/src/generated/zod.ts @@ -1167,6 +1167,7 @@ export const NodeSchema = z.object({ remark: z.string(), scheme: z.enum(['http', 'https']), status: z.string(), + telemetry: z.lazy(() => NodeTelemetrySchema).nullable().optional(), tlsVerifyMode: z.enum(['verify', 'skip', 'pin', 'mtls']), transitive: z.boolean().optional(), unavailableMetrics: z.array(z.string()).optional(), @@ -1196,6 +1197,16 @@ export const NodeClientTrafficSchema = z.object({ }); export type NodeClientTraffic = z.infer; +export const NodeFleetCountsSchema = z.object({ + activeCount: z.number().int(), + clientCount: z.number().int(), + depletedCount: z.number().int(), + disabledCount: z.number().int(), + inboundCount: z.number().int(), + onlineCount: z.number().int(), +}); +export type NodeFleetCounts = z.infer; + export const NodeInboundTrafficSchema = z.object({ down: z.number().int(), id: z.number().int(), @@ -1203,6 +1214,16 @@ export const NodeInboundTrafficSchema = z.object({ }); export type NodeInboundTraffic = z.infer; +export const NodeMasterViewSchema = z.object({ + counts: z.lazy(() => NodeFleetCountsSchema), + panelVersion: z.string().optional(), + telemetry: z.lazy(() => NodeTelemetrySchema).nullable().optional(), + xrayError: z.string().optional(), + xrayState: z.string().optional(), + xrayVersion: z.string().optional(), +}); +export type NodeMasterView = z.infer; + export const NodeMutationRequestSchema = z.object({ address: z.string(), allowPrivateAddress: z.boolean(), @@ -1223,6 +1244,13 @@ export const NodeMutationRequestSchema = z.object({ }); export type NodeMutationRequest = z.infer; +export const NodeOverviewSchema = z.object({ + fleet: z.lazy(() => NodeFleetCountsSchema), + master: z.lazy(() => NodeMasterViewSchema), + nodes: z.array(z.lazy(() => NodeViewSchema).nullable()), +}); +export type NodeOverview = z.infer; + export const NodeSnapshotAttachmentSchema = z.object({ email: z.string(), inboundId: z.number().int(), @@ -1235,6 +1263,27 @@ export const NodeSnapshotStructureSchema = z.object({ }); export type NodeSnapshotStructure = z.infer; +export const NodeTelemetrySchema = z.object({ + cpuPct: z.number().nullable().optional(), + load1: z.number().nullable().optional(), + load15: z.number().nullable().optional(), + load5: z.number().nullable().optional(), + logicalCores: z.number().int().nullable().optional(), + memAvailableBytes: z.number().int().nullable().optional(), + memTotalBytes: z.number().int().nullable().optional(), + memUsedBytes: z.number().int().nullable().optional(), + netDown: z.number().int().nullable().optional(), + netUp: z.number().int().nullable().optional(), + physicalCores: z.number().int().nullable().optional(), + resourceScope: z.string().optional(), + sampleAgeMillis: z.number().int().nullable().optional(), + sampledAt: z.number().int(), + tcpCount: z.number().int().nullable().optional(), + udpCount: z.number().int().nullable().optional(), + uptimeSecs: z.number().int().nullable().optional(), +}); +export type NodeTelemetry = z.infer; + export const NodeTrafficSnapshotV1Schema = z.object({ activeInboundTree: z.record(z.string(), z.array(z.string())), clients: z.array(z.lazy(() => NodeClientTrafficSchema)), @@ -1285,6 +1334,7 @@ export const NodeViewSchema = z.object({ remark: z.string(), scheme: z.string(), status: z.string(), + telemetry: z.lazy(() => NodeTelemetrySchema).nullable().optional(), tlsVerifyMode: z.string(), transitive: z.boolean().optional(), unavailableMetrics: z.array(z.string()).optional(), @@ -1509,6 +1559,7 @@ export const StatusSchema = z.object({ panelVersion: z.string(), publicIP: z.unknown(), resourceScope: z.string().optional(), + sampleAgeMillis: z.number().int().nullable().optional(), swap: z.unknown(), tcpCount: z.number().int(), udpCount: z.number().int(), diff --git a/frontend/src/pages/api-docs/endpoints.ts b/frontend/src/pages/api-docs/endpoints.ts index 91080469e..5dcc424f0 100644 --- a/frontend/src/pages/api-docs/endpoints.ts +++ b/frontend/src/pages/api-docs/endpoints.ts @@ -2082,6 +2082,13 @@ export const sections: readonly Section[] = [ responseSchema: 'NodeView', responseSchemaArray: true, }, + { + method: 'GET', + path: '/panel/api/nodes/overview', + summary: + 'Read the local panel, unique fleet client counts and sampled remote host telemetry.', + responseSchema: 'NodeOverview', + }, { method: 'POST', path: '/panel/api/nodes/mtls/ca', diff --git a/frontend/src/pages/nodes/NodeList.css b/frontend/src/pages/nodes/NodeList.css index 920ac4978..e495fdfab 100644 --- a/frontend/src/pages/nodes/NodeList.css +++ b/frontend/src/pages/nodes/NodeList.css @@ -1,160 +1,652 @@ -.toolbar { - margin-bottom: 12px; - display: flex; - justify-content: space-between; - align-items: center; +@font-face { + font-family: 'Source Sans Pro'; + src: url('./fonts/SourceSansPro-Regular.woff2') format('woff2'); + font-weight: 400; + font-display: swap; } - -.name-cell { - display: flex; - flex-direction: column; -} - -.name-cell .name { - font-weight: 500; -} - -.name-cell .remark { - font-size: 12px; - opacity: 0.65; -} - -.address-header { - display: inline-flex; - align-items: center; - gap: 6px; -} - -.ip-toggle-icon { - cursor: pointer; - font-size: 14px; - opacity: 0.7; -} - -.ip-toggle-icon:hover { - opacity: 1; -} - -.address-hidden { - filter: blur(5px); - transition: filter 0.2s ease; -} - -.address-visible { - filter: none; -} - -.node-cards { - display: flex; - flex-direction: column; - gap: 12px; - margin-top: 4px; -} - -.node-card { - border: 1px solid var(--ant-color-border-secondary); - border-radius: 10px; - padding: 12px; - background: var(--ant-color-fill-quaternary); - display: flex; - flex-direction: column; - gap: 8px; -} - -.card-head { - display: flex; - align-items: center; - gap: 8px; - cursor: pointer; - user-select: none; -} - -.card-expand { - font-size: 12px; - opacity: 0.6; - transition: transform 150ms ease; - flex-shrink: 0; -} - -.card-expand.is-expanded { - transform: rotate(90deg); -} - -.node-name { +@font-face { + font-family: 'Source Sans Pro'; + src: url('./fonts/SourceSansPro-Semibold.woff2') format('woff2'); font-weight: 600; - flex: 1; + font-display: swap; +} +@font-face { + font-family: 'Source Sans Pro'; + src: url('./fonts/SourceSansPro-Bold.woff2') format('woff2'); + font-weight: 700; + font-display: swap; +} +.nodes-page.is-dark:not(.is-ultra) { + --bg-page: #1c1e23; +} + +@media (min-width: 769px) { + .nodes-page .ant-sidebar:not(.sidebar-pinned) { + --sider-rail: 69px !important; + } + + .nodes-page .ant-sidebar:not(.sidebar-pinned) .ant-layout-sider-collapsed { + flex-basis: 69px !important; + width: 69px !important; + min-width: 69px !important; + max-width: 69px !important; + } + + .nodes-page .content-area { + padding-inline-start: 23px; + } +} +.nodes-overview { + --node-fg: var(--node-text); + --node-secondary: var(--node-muted); + --node-card: var(--node-surface); + --node-field: var(--node-header-bg); + --node-line: var(--node-border); + --node-fleet: var(--node-fleet-bg); + --node-button: var(--node-accent); + --node-add-bg: #1269eb; + --node-link: #185ea8; + --node-good: #317a19; + --node-bad: #b42e35; + --node-purple: #722ed1; + --node-group-bg: #ebedf0; + --node-active-bg: #eef6e9; + --node-disabled-bg: #eeeff2; + --node-depleted-bg: #f9ebeb; + --node-online-bg: #e7f0fa; min-width: 0; + font: + 400 13px/1.25 'Source Sans Pro', + system-ui, + sans-serif; + color: var(--node-fg); +} +.dark .nodes-overview, +.nodes-page.is-dark:not(.is-ultra) .nodes-overview { + --node-fg: #d6d9e0; + --node-secondary: #9296a0; + --node-card: #23252b; + --node-field: #2b2d32; + --node-line: #353841; + --node-fleet: #252b34; + --node-button: #1677ff; + --node-link: #8cb8ff; + --node-good: #66b740; + --node-bad: #eb6469; + --node-purple: #bb9df5; + --node-group-bg: #30333b; + --node-active-bg: #172d12; + --node-disabled-bg: #37393e; + --node-depleted-bg: #401a1c; + --node-online-bg: #102d4b; +} +.nodes-heading, +.nodes-toolbar, +.nodes-footnote { + display: flex; + align-items: center; + gap: 12px; + margin-inline-start: 12px; +} +.nodes-heading { + align-items: start; + justify-content: space-between; + margin-block-end: 21px; +} +.nodes-heading h1 { + margin: 0; + font: + 600 25px/34px 'Source Sans Pro', + system-ui, + sans-serif; +} +.nodes-heading p { + margin: 1px 0 0; + color: var(--node-secondary); + font-size: 13px; + line-height: 21px; +} +.nodes-heading-actions { + display: flex; + gap: 12px; + padding-block-start: 4px; +} +.nodes-heading .ant-btn, +.nodes-toolbar .ant-btn { + font-family: inherit; + border-radius: 7px; +} +.nodes-heading .ant-btn { + height: 38px; +} +.nodes-heading .nodes-add { + width: 138px; + background: var(--node-add-bg); + font-weight: 600; +} +.nodes-heading .nodes-add:hover { + background: #145fd1; +} +.nodes-heading .nodes-mtls { + width: 145px; + background: var(--node-card); + border-color: var(--node-line); +} +.nodes-toolbar { + min-height: 36px; + margin-block-end: 13px; + flex-wrap: wrap; +} +.nodes-toolbar .ant-input-affix-wrapper { + width: min(278px, 100%); +} +.nodes-toolbar .ant-input-affix-wrapper, +.nodes-toolbar .ant-select { + height: 36px; + border-radius: 7px; + font: inherit; + color: var(--node-fg); + background: var(--node-field); + border-color: var(--node-line); +} +.nodes-toolbar .ant-input::placeholder, +.nodes-toolbar .ant-input-prefix, +.node-registered { + color: var(--node-secondary); +} +.nodes-toolbar .ant-input { + font: inherit; +} +.nodes-toolbar .ant-select { + width: 148px; +} +.nodes-toolbar .ant-select-selector { + background: transparent; +} +.node-registered { + margin-inline-start: auto; +} +.nodes-table-card { + padding: 15px 11px 30px; + border: 1px solid var(--node-line); + border-radius: 12px; + background: var(--node-card); +} +.nodes-table-scroll { + overflow-x: auto; + container-type: inline-size; +} +.node-fleet-table { + width: 100%; + min-width: 920px; + table-layout: fixed; + border-spacing: 0; + color: var(--node-fg); +} +.node-fleet-table th, +.node-fleet-table td { + padding: 0 8px; + text-align: start; + vertical-align: middle; + overflow-wrap: anywhere; +} +.node-fleet-table thead th { + height: 44px; + padding-inline: 1px; + background: var(--node-field); + color: var(--node-secondary); + text-align: center; + font-size: 12px; + font-weight: 600; +} +.node-fleet-table thead th:nth-child(6), +.node-fleet-table thead th:nth-child(8) { + font-weight: 700; +} +.node-fleet-table thead th:first-child { + border-start-start-radius: 8px; + border-end-start-radius: 8px; +} +.node-fleet-table thead th:last-child { + border-start-end-radius: 8px; + border-end-end-radius: 8px; +} +.node-fleet-table tbody > tr:not(.node-history-row) { + height: 70px; +} +.node-fleet-table td, +.node-fleet-table .node-name-cell { + border-block-end: 1px solid var(--node-line); +} +.node-row-remote > td:first-child { + padding-inline-end: 0; +} +.node-fleet-table .node-enabled { + text-align: center; + color: var(--node-secondary); +} +.node-fleet-table .node-enabled .ant-switch { + min-width: 34px; + height: 18px; +} +.node-fleet-table .node-enabled .ant-switch-handle { + width: 14px; + height: 14px; +} +.node-fleet-table .node-enabled .ant-switch.ant-switch-checked { + background: var(--node-button); +} +.node-row-fleet > * { + background: var(--node-fleet); +} +.node-row-fleet td:first-child { + box-shadow: inset 3px 0 var(--node-button); +} +.node-row-fleet > td:nth-child(5) { + padding-inline-end: 2px; +} +[dir='rtl'] .node-row-fleet td:first-child { + box-shadow: inset -3px 0 var(--node-button); +} +.node-actions-heading, +.node-readonly-action, +.node-icon-action, +.node-expander, +.node-status-button { + border: 0; + padding: 0; + background: transparent; + color: inherit; + font: inherit; + cursor: pointer; +} +.node-actions, +.node-system-action, +.node-status-button { + display: flex; + align-items: center; +} +.node-actions { + flex-wrap: wrap; + row-gap: 3px; +} +.node-actions > .ant-checkbox-wrapper { + margin-inline: 8px 5px; +} +.node-actions .ant-checkbox-inner { + width: 16px; + height: 16px; + background: var(--node-card); + border-color: #636b7b; +} +.node-actions .ant-checkbox-checked .ant-checkbox-inner { + background: var(--node-button); + border-color: var(--node-button); +} +.node-system-action { + gap: 12px; + padding-inline-start: 9px; + color: var(--node-secondary); +} +.node-system-badge { + min-width: 52px; + padding: 4px 12px; + border-radius: 4px; + color: var(--node-fg); + background: var(--node-group-bg); + font-size: 10px; + font-weight: 600; + text-align: center; + text-transform: uppercase; +} +.node-sigma { + color: var(--node-link); + font-size: 18px; + font-weight: 600; +} +.node-icon-action, +.node-expander { + display: inline-grid; + place-content: center; + width: 18px; + height: 24px; + font-size: 15px; +} +.node-icon-delete { + color: var(--node-bad); +} +.node-icon-action:disabled { + color: var(--node-secondary); + opacity: 0.5; + cursor: default; +} +.node-expander { + height: 18px; + border: 1px solid var(--node-line); + border-radius: 4px; + background: var(--node-field); + color: var(--node-secondary); + font-size: 13px; +} +.node-name, +.node-cell-stack { + display: flex; + flex-direction: column; + min-width: 0; +} +.node-name { + gap: 4px; + font-size: 12px; + font-weight: 600; +} +.node-name > span, +.node-name > small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } - -.card-actions { - display: flex; - align-items: center; - gap: 8px; - flex-shrink: 0; +.node-row-fleet .node-name > span, +.node-row-master .node-name > span { + font-size: 14px; } - -.row-action-trigger { - font-size: 20px; - cursor: pointer; +.node-row-fleet .node-name > small { + font-size: 11px; + white-space: normal; } - -.card-stats { - display: flex; - flex-direction: column; - gap: 6px; -} - -.stat-row { - display: flex; - align-items: center; - flex-wrap: wrap; - gap: 6px; -} - -.stat-label { +.node-name small { + color: var(--node-secondary); font-size: 10px; - text-transform: uppercase; - letter-spacing: 0.04em; - opacity: 0.6; - min-width: 96px; - flex-shrink: 0; + font-weight: 400; } - -.card-stats .ant-tag { +.node-open-link:any-link { + color: var(--node-link); + font-size: 10px; + white-space: nowrap; +} +.node-open-link:hover, +.node-open-link:focus-visible { + text-decoration: underline; +} +.node-open-link span { + font-size: 13px; + font-weight: 600; +} +.node-status-button { + gap: 5px; + width: 100%; + text-align: start; + font-size: 11px; + font-weight: 600; +} +.node-status-button[data-status='online'] { + color: var(--node-good); +} +.node-status-button[data-status='offline'] { + color: var(--node-bad); +} +.node-status-button .online-dot, +.node-status-button .xray-error-dot, +.node-status-button .ant-badge-status-dot { + display: inline-block; + width: 8px; + height: 8px; + flex: 0 0 8px; + border-radius: 50%; +} +.node-status-button .online-dot { + background: var(--node-good); +} +.node-status-button .xray-error-dot { + background: var(--node-purple); +} +.node-status-info { + margin-inline-start: auto; + color: var(--node-secondary); + font-size: 10px; +} +.node-status-popup .ant-tooltip-container { + width: min(258px, 90vw); + padding: 12px 14px; + border: 1px solid #414550; + border-radius: 8px; + color: #d6d9e0; + font: + 400 11px/1.4 'Source Sans Pro', + system-ui, + sans-serif; +} +.node-status-tooltip h3 { + margin: 0 0 5px; + color: #a6aab4; + font: + 600 11px 'Source Sans Pro', + system-ui, + sans-serif; +} +.node-status-tooltip dl { margin: 0; } - -.card-history { - margin-top: 4px; - padding-top: 8px; - border-top: 1px solid var(--ant-color-border-secondary); -} - -.card-empty { - text-align: center; - color: var(--ant-color-text-secondary); - padding: 24px 12px; +.node-status-tooltip dl > div { display: flex; - flex-direction: column; - align-items: center; - gap: 8px; + justify-content: space-between; + gap: 25px; + line-height: 23px; } - -.node-network-speed { - display: inline-grid; - row-gap: 2px; - text-align: start; - line-height: 1.25; +.node-status-tooltip dd { + margin: 0; + font-size: 12px; + font-weight: 600; } - -.node-network-direction { - display: grid; - grid-template-columns: 1em auto; - column-gap: 4px; - align-items: center; - white-space: nowrap; +.node-status-tooltip dt { + color: #a6aab4; +} +.node-hardware { + gap: 6px; font-variant-numeric: tabular-nums; } +.node-cpu { + font: + 400 11px/15px 'Source Sans Pro', + system-ui, + sans-serif; +} +.node-ram { + font: + 400 10px/13px 'Source Sans Pro', + system-ui, + sans-serif; +} +.node-memory-detail { + color: var(--node-secondary); + font-size: 9px; +} +.node-network-speed, +.node-runtime, +.node-connections, +.node-system-clients { + gap: 5px; + font-size: 10px; +} +.node-network-speed { + display: inline-grid; + font-variant-numeric: tabular-nums; +} +.node-network-direction { + display: flex; + align-items: center; + gap: 3px; +} +.node-network-up { + color: var(--node-link); +} +.node-row-fleet .node-network-speed, +.node-row-master .node-network-speed { + font-size: 12px; +} +.node-connections > span:nth-child(-n + 2) { + font-weight: 600; +} +.node-connection-load, +.node-runtime small { + color: var(--node-secondary); + font-size: 9px; +} +.node-runtime .node-panel-line { + display: flex; + align-items: center; + gap: 3px; +} +.node-runtime .node-icon-action { + width: 13px; + height: 13px; + color: var(--node-link); + font-size: 11px; +} +.node-system-clients { + font-size: 11px; +} +.node-system-clients small { + color: var(--node-secondary); + font-size: 10px; +} +.node-client-counts { + display: grid; + grid-template-columns: 52fr 54fr 58fr; + grid-template-rows: repeat(2, 21px); + gap: 4px 6px; + align-items: center; +} +.node-count-total { + grid-column: 1; + grid-row: 1 / span 2; +} +.node-client-counts .ant-tag { + margin: 0; + padding-inline: 2px; + text-align: center; + line-height: 19px; + font: + 400 11px/19px 'Source Sans Pro', + system-ui, + sans-serif; + color: var(--node-fg); + background: var(--node-disabled-bg); +} +.node-client-counts .node-count-active { + grid-column: 2; + grid-row: 1; + background: var(--node-active-bg); + color: var(--node-good); +} +.node-client-counts .node-count-disabled { + grid-column: 3; + grid-row: 1; +} +.node-client-counts .node-count-depleted { + grid-column: 2; + grid-row: 2; + background: var(--node-depleted-bg); + color: var(--node-bad); +} +.node-client-counts .node-count-online { + grid-column: 3; + grid-row: 2; + background: var(--node-online-bg); + color: var(--node-link); +} +.node-history-row td { + padding: 12px; +} +.nodes-footnote { + justify-content: space-between; + margin-block-start: 9px; + color: var(--node-secondary); + font-size: 11px; + line-height: 22px; +} +@container (max-width: 1205px) { + .node-actions > .ant-checkbox-wrapper { + margin-inline: 4px; + } + + .node-actions > .node-icon-action { + width: 17px; + } +} +@media (max-width: 650px) { + .nodes-heading { + flex-wrap: wrap; + } + .nodes-heading-actions { + flex-wrap: wrap; + } + .node-registered { + margin-inline-start: 0; + } +} +@container (width < 920px) { + .node-fleet-table, + .node-fleet-table thead, + .node-fleet-table tbody, + .node-fleet-table tr, + .node-fleet-table .node-history-row td { + display: block; + min-width: 0; + } + .node-fleet-table colgroup { + display: none; + } + .node-fleet-table thead th:not(:first-child) { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + } + .node-fleet-table thead th:first-child { + display: flex; + align-items: center; + padding-inline: 10px; + border-radius: 8px; + } + .node-fleet-table tbody > tr:not(.node-history-row) { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 10px; + height: auto; + margin-block-start: 8px; + padding: 10px; + border: 1px solid var(--node-line); + border-radius: 8px; + } + .node-row-fleet { + background: var(--node-fleet); + } + .node-fleet-table tbody td, + .node-fleet-table .node-name-cell { + min-width: 0; + padding: 0; + border: 0; + text-align: start; + } + .node-fleet-table .node-name-cell, + .node-fleet-table tbody td:first-child { + grid-column: 1 / -1; + } + .node-fleet-table .node-name-cell { + grid-row: 1; + } + .node-fleet-table td[data-label]::before { + display: block; + margin-block-end: 4px; + color: var(--node-secondary); + font-size: 11px; + content: attr(data-label); + } + .node-fleet-table .node-row-fleet td:first-child { + box-shadow: none; + } + .node-fleet-table .node-history-row td { + padding: 10px; + } +} diff --git a/frontend/src/pages/nodes/NodeList.stories.tsx b/frontend/src/pages/nodes/NodeList.stories.tsx new file mode 100644 index 000000000..932e3c954 --- /dev/null +++ b/frontend/src/pages/nodes/NodeList.stories.tsx @@ -0,0 +1,169 @@ +import type { Meta, StoryObj } from '@storybook/react-vite'; +import { expect, within } from 'storybook/test'; +import { ConfigProvider } from 'antd'; +import { useState } from 'react'; +import type { NodeRecord } from '@/schemas/node'; +import NodeList from './NodeList'; + +const counts = { + clientCount: 7100, + inboundCount: 40, + activeCount: 6050, + disabledCount: 50, + depletedCount: 1000, + onlineCount: 210, +}; +const noop = () => {}; + +function Fixture({ rtl }: { rtl?: boolean }) { + const [selectedIds, setSelectedIds] = useState([]); + const [now] = useState(Date.now); + const nodes: NodeRecord[] = [ + { + id: 1, + name: 'Finland edge', + status: 'online', + enable: true, + xrayVersion: '26.1.1', + panelVersion: '3.12.0', + latencyMs: 42, + lastHeartbeat: Math.floor(now / 1000) - 2, + scheme: 'https', + address: '2001:db8::3', + port: 2053, + basePath: '/edge/', + telemetry: { + sampledAt: now, + cpuPct: 0, + logicalCores: 8, + memUsedBytes: 4 * 2 ** 30, + memTotalBytes: 16 * 2 ** 30, + netUp: 1024, + netDown: 2048, + tcpCount: 0, + udpCount: 21, + load1: 0.25, + load5: 0.15, + load15: 0.1, + uptimeSecs: 5000, + }, + clientCount: 3077, + onlineCount: 31, + onlineTotalCount: 53, + }, + { + id: 2, + name: 'Frankfurt', + status: 'online', + enable: true, + panelVersion: '3.13.0', + scheme: 'https', + address: 'frankfurt-with-a-very-long-hostname.example.test', + port: 443, + telemetry: { sampledAt: now, cpuPct: 40, logicalCores: 4, tcpCount: 4, load1: 0.75 }, + }, + { + id: 3, + name: 'This-is-an-intentionally-long-node-name-without-spaces', + status: 'offline', + enable: true, + lastError: 'Remote panel did not respond', + }, + { + id: 4, + name: 'Standby', + status: 'online', + enable: false, + telemetry: { sampledAt: now, cpuPct: 100, tcpCount: 9 }, + }, + ]; + return ( + +
+ +
+
+ ); +} + +const meta = { title: 'Nodes/Fleet Monitoring', component: Fixture } satisfies Meta; +export default meta; +type Story = StoryObj; + +export const Desktop: Story = { + play: async ({ canvasElement, userEvent }) => { + const canvas = within(canvasElement); + const row = canvas.getByRole('row', { name: /All nodes/ }); + await expect(within(row).getByText('3/5 reporting')).toBeVisible(); + await expect(within(row).getByText('20.0%')).toBeVisible(); + await expect(within(row).queryByRole('checkbox')).toBeNull(); + await expect( + within(canvas.getByRole('row', { name: /Master/ })).queryByRole('switch'), + ).toBeNull(); + const edge = canvas.getByRole('row', { name: /Finland edge/ }); + const link = within(edge).getByRole('link', { name: 'Open' }); + await expect(link).toHaveAttribute('href', 'https://[2001:db8::3]:2053/edge/'); + await expect(link).toHaveAttribute('rel', 'noopener noreferrer'); + const status = within(edge).getByRole('button', { name: 'Online' }); + await userEvent.click(status); + await expect(await within(canvasElement.ownerDocument.body).findByText('42 ms')).toBeVisible(); + const input = canvas.getByRole('searchbox', { name: 'Search' }); + await userEvent.click(input); + for (const viewport of [1280, 1440, 1664, 1920]) { + const container = canvas.getByRole('region', { name: 'Nodes' }); + container.style.width = `${viewport - 260}px`; + const table = container.querySelector('.nodes-table-scroll') as HTMLElement; + await expect(table.scrollWidth).toBeLessThanOrEqual(table.clientWidth + 1); + container.style.width = ''; + } + await userEvent.type(input, 'Frankfurt'); + await expect(canvas.queryByText('Finland edge')).toBeNull(); + await expect(canvas.getByText('3/5 reporting')).toBeVisible(); + await userEvent.clear(input); + }, +}; + +export const RTL: Story = { args: { rtl: true }, globals: { theme: 'light' } }; diff --git a/frontend/src/pages/nodes/NodeList.tsx b/frontend/src/pages/nodes/NodeList.tsx index 3ae461c32..00da6117f 100644 --- a/frontend/src/pages/nodes/NodeList.tsx +++ b/frontend/src/pages/nodes/NodeList.tsx @@ -1,39 +1,58 @@ -import { useCallback, useMemo, useState } from 'react'; +import { Fragment, useMemo, useState, type CSSProperties, type ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; -import { Badge, Button, Card, Dropdown, Modal, Space, Switch, Table, Tag, Tooltip } from 'antd'; +import { + Badge, + Checkbox, + Button, + Dropdown, + Input, + Select, + Switch, + Tag, + Tooltip, + theme, +} from 'antd'; import type { BadgeProps } from 'antd'; -import type { ColumnsType } from 'antd/es/table'; import { ApartmentOutlined, - ClusterOutlined, CloudDownloadOutlined, DeleteOutlined, EditOutlined, ExclamationCircleOutlined, EyeInvisibleOutlined, EyeOutlined, + LockOutlined, InfoCircleOutlined, + SearchOutlined, MoreOutlined, PlusOutlined, ReloadOutlined, - RightOutlined, SafetyCertificateOutlined, TeamOutlined, ThunderboltOutlined, } from '@ant-design/icons'; import NodeHistoryPanel from './NodeHistoryPanel'; -import NodeNetworkSpeed from './NodeNetworkSpeed'; +import { NetworkSpeedValues } from './NodeNetworkSpeed'; +import { + aggregateTelemetry, + freshTelemetry, + reportingSample, + useTelemetryClock, +} from './fleetTelemetry'; +import type { NodeTelemetry, NodeFleetCounts, NodeMasterView } from '@/generated/types'; +import { SizeFormatter } from '@/utils'; +import { withBasePath } from '@/api/http-init'; import type { NodeRecord } from '@/api/queries/useNodesQuery'; import { isPanelUpdateAvailable } from '@/lib/panel-version'; -import { activateOnKey } from '@/utils/a11y'; import './NodeList.css'; interface NodeListProps { nodes: NodeRecord[]; + master?: NodeMasterView; + fleet?: NodeFleetCounts; nodesUpdatedAt?: number; loading?: boolean; - isMobile?: boolean; latestVersion?: string; selectedIds: number[]; onSelectionChange: (ids: number[]) => void; @@ -57,18 +76,15 @@ function isUpdateEligible(n: NodeRecord): boolean { // A node also serves clients on inbounds this panel does not sync; when it reports // more online than the synced count, both show as "synced / total". -function onlineCounts(n: NodeRecord): { label: string; synced: number; total: number } | null { +function onlineCounts( + n: Pick, +): { label: string; synced: number; total: number } | null { const synced = n.onlineCount || 0; const total = Math.max(n.onlineTotalCount || 0, synced); if (!total) return null; return { label: total > synced ? `${synced} / ${total}` : String(synced), synced, total }; } -interface NodeRow extends NodeRecord { - url: string; - key: string | number; -} - function badgeStatus(status?: string): BadgeProps['status'] { switch (status) { case 'online': @@ -132,16 +148,12 @@ function StatusLabel({ status, xrayState }: HealthProps) { ? t('pages.nodes.statusValues.xrayError') : t('pages.nodes.statusValues.xrayStopped'); return ( - + {t('pages.nodes.statusValues.online')} ({detail}) ); } - return ( - - {t('pages.nodes.statusValues.online')} - - ); + return {t('pages.nodes.statusValues.online')}; } // A sub-node's status is free text from its parent node: show it as unknown, not as a key. return ( @@ -153,13 +165,13 @@ function StatusLabel({ status, xrayState }: HealthProps) { ); } -function formatPct(p?: number, available = true): string { +function formatPct(p?: number | null, available = true): string { if (!available) return '—'; if (typeof p !== 'number' || Number.isNaN(p)) return '-'; return `${p.toFixed(1)}%`; } -function formatUptime(secs?: number, available = true): string { +function formatUptime(secs?: number | null, available = true): string { if (!available) return '—'; if (!secs) return '-'; const days = Math.floor(secs / 86400); @@ -188,32 +200,306 @@ function useRelativeTime() { ); } -function OnlineTag({ node, compact }: { node: NodeRecord; compact?: boolean }) { +function OnlineTag({ node }: { node: Pick }) { const { t } = useTranslation(); const counts = onlineCounts(node); if (!counts) return null; - const tag = compact ? ( - - {counts.label} - - ) : ( - - {counts.label} {t('online')} - + const title = + counts.total > counts.synced + ? t('pages.nodes.onlineOnNode', { synced: counts.synced, total: counts.total }) + : t('online'); + return ( + + {counts.label} + ); - if (counts.total > counts.synced) { - const title = t('pages.nodes.onlineOnNode', { synced: counts.synced, total: counts.total }); - return {tag}; - } - // The compact tag is a bare number, so it still needs to say what it counts. - return compact ? {tag} : tag; } +type FleetRow = + | { kind: 'remote'; key: string | number; node: NodeRecord; telemetry?: NodeTelemetry } + | { kind: 'master'; key: 'master'; host: NodeMasterView; telemetry?: NodeTelemetry } + | { + kind: 'fleet'; + key: 'fleet'; + counts: NodeFleetCounts; + telemetry: NodeTelemetry; + reporting: number; + registered: number; + cpuHosts: number; + memoryHosts: number; + panelVersions: string[]; + xrayVersions: string[]; + }; + +function HealthStatus({ + node, + relativeTime, +}: { + node: HealthProps & + Partial>; + relativeTime: (ts?: number) => string; +}) { + const { t } = useTranslation(); + const status = node.enable === false && node.status !== 'offline' ? 'disabled' : node.status; + const { tip, iconColor } = statusIssue(node); + return ( + +

{t('pages.nodes.fleet.connectionDetails')}

+ {node.id !== undefined && ( +
+
+
{t('pages.nodes.latency')}
+
{node.latencyMs ? node.latencyMs + ' ms' : '—'}
+
+
+
{t('pages.nodes.lastHeartbeat')}
+
{relativeTime(node.lastHeartbeat)}
+
+
+ )} + {node.xrayState && ( +
+ {t('pages.nodes.xrayVersion')} · {node.xrayState} +
+ )} + {tip &&
{tip}
} + + } + > + +
+ ); +} + +function Hardware({ + sample, + fleet, + system, +}: { + sample?: NodeTelemetry; + fleet: boolean; + system: boolean; +}) { + const { t, i18n } = useTranslation(); + const total = sample?.memTotalBytes; + const used = sample?.memUsedBytes; + const hasMemory = used != null && total != null && total > 0 && used <= total; + const memorySize = (value: number) => { + if (!total || total < SizeFormatter.ONE_GB) return SizeFormatter.sizeFormat(value); + const useTB = total >= SizeFormatter.ONE_TB; + return new Intl.NumberFormat(i18n.language, { + maximumFractionDigits: 1, + style: 'unit', + unit: useTB ? 'terabyte' : 'gigabyte', + unitDisplay: 'short', + }).format(value / (useTB ? SizeFormatter.ONE_TB : SizeFormatter.ONE_GB)); + }; + return ( +
+
+ {fleet ? t('pages.nodes.fleet.cpuAverage') : t('pages.nodes.cpu')}{' '} + {formatPct(sample?.cpuPct, sample?.cpuPct != null)} + {sample?.logicalCores != null && ( + <> · {t('pages.nodes.fleet.logicalCores', { cores: sample.logicalCores })} + )} +
+
+ RAM{' '} + {hasMemory ? ( + + {memorySize(used)} / {memorySize(total)} · {formatPct((100 * used) / total)} + + ) : ( + '—' + )} +
+ {system && hasMemory && ( + + {sample?.memAvailableBytes != null + ? t('pages.nodes.fleet.availableMemory', { + size: SizeFormatter.sizeFormat(sample?.memAvailableBytes), + }) + : t('pages.nodes.fleet.remainingMemory', { + size: SizeFormatter.sizeFormat(total - used), + })} + + )} +
+ ); +} + +function Connections({ sample, fleet }: { sample?: NodeTelemetry; fleet: boolean }) { + const { t, i18n } = useTranslation(); + const count = new Intl.NumberFormat(i18n.language); + return ( +
+ + TCP {sample?.tcpCount == null ? '—' : count.format(sample.tcpCount)} + + + UDP {sample?.udpCount == null ? '—' : count.format(sample.udpCount)} + + + {fleet ? t('pages.nodes.fleet.loadSum') : t('pages.nodes.fleet.load')}{' '} + + {[sample?.load1, sample?.load5, sample?.load15] + .map((v) => v?.toFixed(2) ?? '—') + .join(' / ')} + + +
+ ); +} + +function ClientCounts({ + counts, +}: { + counts: Pick< + NodeRecord, + | 'clientCount' + | 'activeCount' + | 'disabledCount' + | 'depletedCount' + | 'onlineCount' + | 'onlineTotalCount' + >; +}) { + const { t } = useTranslation(); + return ( +
+ + {counts.clientCount ?? 0} + + {!!counts.activeCount && ( + + {counts.activeCount} + + )} + {!!counts.disabledCount && ( + + {counts.disabledCount} + + )} + {!!counts.depletedCount && ( + + {counts.depletedCount} + + )} + +
+ ); +} + +function panelUrl(node: NodeRecord) { + if ( + (node.scheme !== 'https' && node.scheme !== 'http') || + !node.address || + !node.port || + !Number.isInteger(node.port) || + node.port < 1 || + node.port > 65535 || + /[\s/?#@\\]/.test(node.address) + ) + return undefined; + const address = + node.address.includes(':') && !node.address.startsWith('[') + ? '[' + node.address + ']' + : node.address; + try { + const origin = new URL(node.scheme + '://' + address + ':' + node.port); + const path = node.basePath || '/'; + if (!path.startsWith('/') || path.startsWith('//') || /[\\?#\p{Cc}]/u.test(path)) + return undefined; + return origin.origin + path; + } catch { + return undefined; + } +} + +function sampleVersions( + rows: (NodeRecord | NodeMasterView)[], + key: 'panelVersion' | 'xrayVersion', +) { + return [ + ...new Set(rows.map((row) => row[key]).filter((version): version is string => !!version)), + ]; +} + +const columnWidths = [ + { key: 'actions', px: 148 }, + { key: 'enabled', px: 52 }, + { key: 'node', px: 118 }, + { key: 'address', px: 54 }, + { key: 'status', px: 104 }, + { key: 'hardware', px: 160 }, + { key: 'traffic', px: 120 }, + { key: 'connections', px: 125 }, + { key: 'runtime', px: 145 }, + { key: 'clients', px: 200 }, +]; + +function RowAction({ + label, + icon, + disabled, + danger, + onClick, +}: { + label: string; + icon: ReactNode; + disabled?: boolean; + danger?: boolean; + onClick: () => void; +}) { + return ( + + ); +} + +const canSelect = (row: FleetRow) => + row.kind === 'remote' && !row.node.transitive && isUpdateEligible(row.node); + export default function NodeList({ nodes, + master, + fleet, nodesUpdatedAt, loading = false, - isMobile = false, latestVersion = '', selectedIds, onSelectionChange, @@ -228,718 +514,594 @@ export default function NodeList({ onRestart, restartingIds = noRestarts, }: NodeListProps) { - const { t } = useTranslation(); + const { t, i18n } = useTranslation(); + const { token } = theme.useToken(); const relativeTime = useRelativeTime(); - + const [search, setSearch] = useState(''); + const [filter, setFilter] = useState('all'); + const [opened, setOpened] = useState>(() => new Set()); const [showAddress, setShowAddress] = useState(false); - const [statsNodeId, setStatsNodeId] = useState(null); - const [expandedIds, setExpandedIds] = useState>(new Set()); - - const restartItems = useCallback( - (node: NodeRecord) => - (['xray', 'panel'] as const).map((target) => ({ - key: `restart-${target}`, - icon: , - label: t(`pages.nodes.${target === 'xray' ? 'restartXray' : 'restartPanel'}`), - disabled: !node.enable || !!node.transitive || restartingIds.has(node.id), - onClick: () => onRestart(node, target), - })), - [t, onRestart, restartingIds], + const hasNodes = nodes.length > 0; + const samples = useMemo( + () => (nodes.length ? [master?.telemetry, ...nodes.map((node) => node.telemetry)] : []), + [master, nodes], ); + const now = useTelemetryClock(samples, nodesUpdatedAt); - // Map a direct node's GUID to its display name so a transitive sub-node can show - // which parent it is reached through (#4983); the master walks one level only. - const nameByGuid = useMemo(() => { - const m = new Map(); - for (const n of nodes) if (n.guid && !n.transitive) m.set(n.guid, n.name || n.guid); - return m; - }, [nodes]); + const rows = useMemo(() => { + // Fleet monitoring, including Master, is shown only after a remote is registered. + if (!nodes.length) return []; + const masterTelemetry = freshTelemetry(master?.telemetry, now, nodesUpdatedAt); + const remote = nodes.map((node): FleetRow & { kind: 'remote' } => ({ + kind: 'remote', + key: node.transitive ? 't-' + node.guid : node.id, + node, + telemetry: + node.enable && node.status === 'online' + ? freshTelemetry(node.telemetry, now, nodesUpdatedAt) + : undefined, + })); + const results: FleetRow[] = []; + if (fleet) { + const reported = remote.filter((row) => reportingSample(row.telemetry)); + const reportedSamples = [masterTelemetry, ...reported.map((row) => row.telemetry)].filter( + reportingSample, + ); + const hosts = [ + ...reported.map((row) => row.node), + ...(master && reportingSample(masterTelemetry) ? [master] : []), + ]; + results.push({ + kind: 'fleet', + key: 'fleet', + counts: fleet, + registered: nodes.length + 1, + reporting: reportedSamples.length, + ...aggregateTelemetry(reportedSamples), + panelVersions: sampleVersions(hosts, 'panelVersion'), + xrayVersions: sampleVersions(hosts, 'xrayVersion'), + }); + } + if (master) + results.push({ kind: 'master', key: 'master', host: master, telemetry: masterTelemetry }); - // Order direct nodes first, each immediately followed by its transitive - // sub-nodes, so the table reads as a parent -> child tree without colliding - // with the per-row history expander (transitive nodes carry id 0). - const dataSource = useMemo(() => { - const toRow = (n: NodeRecord): NodeRow => ({ - ...n, - url: `${n.scheme}://${n.address}:${n.port}${n.basePath || '/'}`, - key: n.transitive ? `t-${n.guid || ''}` : n.id, - }); - const childrenByParent = new Map(); - for (const n of nodes) { - if (n.transitive && n.parentGuid) { - const arr = childrenByParent.get(n.parentGuid) || []; - arr.push(n); - childrenByParent.set(n.parentGuid, arr); + const word = search.trim().toLocaleLowerCase(); + const visible = remote.filter( + ({ node }) => + (filter === 'all' || + (node.enable === false ? 'disabled' : (node.status ?? 'unknown')) === filter) && + (!word || + [node.name, node.remark, ...(showAddress ? [node.address] : [])].some((value) => + value?.toLocaleLowerCase().includes(word), + )), + ); + const children = new Map(); + for (const row of visible) { + if (!row.node.transitive || !row.node.parentGuid) continue; + const group = children.get(row.node.parentGuid) ?? []; + group.push(row); + children.set(row.node.parentGuid, group); + } + const inserted = new Set(); + for (const row of visible) { + if (row.node.transitive) continue; + results.push(row); + if (!row.node.guid) continue; + for (const child of children.get(row.node.guid) ?? []) { + if (inserted.has(child.key)) continue; + results.push(child); + inserted.add(child.key); } } - const ordered: NodeRow[] = []; - const added = new Set(); - const push = (n: NodeRecord) => { - const row = toRow(n); - ordered.push(row); - added.add(String(row.key)); + results.push(...visible.filter((row) => row.node.transitive && !inserted.has(row.key))); + return results; + }, [fleet, master, nodes, nodesUpdatedAt, now, search, filter, showAddress]); + + const nameByGuid = useMemo( + () => + new Map(nodes.filter((n) => n.guid && !n.transitive).map((n) => [n.guid, n.name || n.guid])), + [nodes], + ); + + const table = useMemo(() => { + const nf = new Intl.NumberFormat(i18n.language); + const headers = [ + t('pages.nodes.actions'), + t('pages.nodes.enable'), + t('pages.nodes.fleet.node'), + t('pages.nodes.address'), + t('pages.nodes.status'), + t('pages.nodes.fleet.hardware'), + t('pages.inbounds.traffic'), + t('pages.nodes.fleet.connections'), + t('pages.nodes.fleet.runtime'), + t('clients'), + ]; + const selectableIds = rows + .filter(canSelect) + .map((row) => (row.kind === 'remote' ? row.node.id : 0)); + const allSelected = + selectableIds.length > 0 && selectableIds.every((id) => selectedIds.includes(id)); + const toggleAll = () => { + if (allSelected) onSelectionChange(selectedIds.filter((id) => !selectableIds.includes(id))); + else onSelectionChange([...new Set([...selectedIds, ...selectableIds])]); }; - for (const n of nodes) { - if (n.transitive) continue; - push(n); - if (n.guid) for (const child of childrenByParent.get(n.guid) || []) push(child); - } - // Transitive nodes whose parent isn't in the list still get shown. - for (const n of nodes) { - if (n.transitive && !added.has(`t-${n.guid || ''}`)) push(n); - } - return ordered; - }, [nodes]); - - const statsNode = - statsNodeId === null - ? undefined - : dataSource.find((node) => !node.transitive && node.id === statsNodeId); - - function toggleExpanded(id: number) { - setExpandedIds((prev) => { - const next = new Set(prev); - if (next.has(id)) next.delete(id); - else next.add(id); - return next; - }); - } - - const columns = useMemo>( - () => [ - { - title: t('pages.nodes.actions'), - align: 'center', - width: 190, - render: (_value, record) => - record.transitive ? ( - - } style={{ margin: 0 }}> - {t('pages.nodes.subNode')} - - - ) : ( - - - - - {selectedIds.length > 0 && ( - - )} - - - {isMobile ? ( - <> -
- {dataSource.length === 0 ? ( -
- -
{t('noData')}
-
- ) : ( - dataSource.map((record) => - record.transitive ? ( -
-
- - - {record.name} -
- } style={{ margin: 0 }}> - {t('pages.nodes.subNode')} - -
-
-
- ) : ( -
- {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events -- mouse click-to-expand mirrors the keyboard-accessible chevron disclosure button */} -
{ - if (!(e.target as HTMLElement).closest('.card-actions')) - toggleExpanded(record.id); - }} - > - toggleExpanded(record.id))} - /> - - {record.name} -
- - setStatsNodeId(record.id)} - onKeyDown={activateOnKey(() => setStatsNodeId(record.id))} - /> - - onToggleEnable(record, v)} - /> - - {t('pages.nodes.probe')} - - ), - onClick: () => onProbe(record), - }, - ...(isUpdateEligible(record) - ? [ - { - key: 'update', - label: ( - <> - {' '} - {t('pages.nodes.updatePanel')} - - ), - onClick: () => onUpdateNode(record), - }, - ] - : []), - { - key: 'edit', - label: ( - <> - {t('edit')} - - ), - onClick: () => onEdit(record), - }, - { - key: 'delete', - danger: true, - label: ( - <> - {t('delete')} - - ), - onClick: () => onDelete(record), - }, - ], - }} - > -
-
- - {expandedIds.has(record.id) && ( -
- -
- )} -
- ), - ) - )} -
- - setStatsNodeId(null)} +
+
+
+

{t('menu.nodes')}

+ {hasNodes &&

{t('pages.nodes.fleet.subtitle')}

} +
+
+ + +
+
+ {hasNodes && ( + <> +
+ } + aria-label={t('search')} + placeholder={t('pages.nodes.fleet.searchNodes')} + allowClear + value={search} + onChange={(event) => setSearch(event.target.value)} + /> +