mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6972] feat(monitoring): allow selecting network interface for traffic statistics #6555
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6555
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6972
Author: @HamedSanaei
Created: 10/27/2026
Status: 🔄 Open
Base:
main← Head:feat/network-traffic-interface📝 Commits (3)
9fa66c0feat(monitoring): add configurable traffic interface selection4d5f74dfix(monitoring): handle unavailable interfaces consistently1b6ee40chore(merge): update network monitoring with upstream main📊 Changes
63 files changed (+2770 additions, -179 deletions)
View changed files
📝
docs/content/docs/en/config/panel.mdx(+81 -0)📝
docs/content/docs/en/reference/api/server.mdx(+10 -1)➕
docs/public/images/network-traffic-automatic.png(+0 -0)➕
docs/public/images/network-traffic-interface.png(+0 -0)📝
docs/public/openapi.json(+266 -29)📝
frontend/public/openapi.json(+266 -29)📝
frontend/src/api/queries/useAllSettings.ts(+2 -2)➕
frontend/src/api/queries/useNetworkInterfaces.ts(+21 -0)📝
frontend/src/api/queryKeys.ts(+1 -0)📝
frontend/src/generated/examples.ts(+54 -0)📝
frontend/src/generated/schemas.ts(+189 -0)📝
frontend/src/generated/types.ts(+49 -4)📝
frontend/src/generated/zod.ts(+53 -12)📝
frontend/src/models/setting.ts(+3 -1)📝
frontend/src/models/status.ts(+3 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+9 -3)📝
frontend/src/pages/index/ThroughputCard.tsx(+29 -7)📝
frontend/src/pages/index/useOverviewHistory.ts(+3 -4)📝
frontend/src/pages/settings/GeneralTab.tsx(+3 -0)➕
frontend/src/pages/settings/NetworkTrafficSettings.tsx(+101 -0)...and 43 more files
📄 Description
Summary
Add legacy, automatic, and manual network interface selection to system traffic monitoring, with persisted settings, an authenticated interface picker, and consistent dashboard, history, Telegram, Discord, status API, WebSocket, and node-history behavior. Rebase throughput and packet-rate samples when their source changes or counters reset.
Why
System traffic currently sums interfaces using hard-coded exclusions. On stacked-network setups, including Azure Accelerated Networking, a synthetic interface and its SR-IOV interface can represent the same traffic and be counted twice. Administrators can now opt into one appropriate interface while existing installations and new installations keep legacy aggregation by default.
Closes #6906
Automatic route selection was inspired by IPv6Monitor. The implementation uses the existing Go netlink dependency; it does not copy that project's daemon, database, or nftables accounting.
Type of change
Areas affected
Discord system reports are updated as well. Client quota, billing, inbound traffic accounting, and Xray configuration are unchanged.
How was this tested?
Development followed red → green → refactor. Regression tests reject the original doubled aggregation in single-interface modes and the original throughput subtraction on incompatible samples.
make verify: Go tests/lint/build, frontend lint/format/typecheck, 2,033 frontend tests, production and Storybook builds, generated API checks, and published OpenAPI consistency.make race: passed across Go packages.go vet -p=2 ./...: passed.make node-e2e: passed with real master/node processes, including global traffic heartbeat chains.pnpm typecheck,pnpm lint,pnpm format:check,pnpm test(112 tests), andpnpm buildpassed.Coverage includes the 30 GiB + 30 GiB stacked-interface fixture; exact physical/virtual manual selection; IPv4/IPv6 routes, metrics, ECMP, unusable routes and unsigned priorities; mode/route/device changes; byte and packet counter resets; disappearing/reappearing interfaces; invalid elapsed time; settings persistence after reopening the database; invalid input rejection; unchanged missing manual selections; interactive Discord status distinguishing unavailable traffic from measured zero; omitted-field compatibility under an interleaved settings update; authenticated endpoint scope; and unavailable versus measured-zero values in history and reports.
To exercise the feature:
GET /panel/api/server/networkInterfacesusing an admin session/token. It returns the existing envelope with names/up state and the automatic result or error. Anonymous, monitor-scope, and node-sync tokens cannot list interfaces.Screenshots / recordings
Local Chromium previews of the actual settings component with example interface names:
Breaking changes
None. Legacy aggregation remains the default, using the same interface exclusions. Two settings use the existing key/value table; no tables, columns, or migrations are added. Older API clients omitting the new pair preserve the saved selection; explicit
networkTrafficMode: "legacy"restores aggregation. Status metadata and the admin-only interface-list route are additive, and older responses remain accepted by the frontend.New manual selections must exist when saved. An unchanged saved manual selection may remain unavailable, allowing unrelated settings to be edited without replacing that selection.
Network interface selection is machine-bound for the existing keep-host-settings database import option.
Automatic selection is a Linux main-routing-table heuristic, not a full policy-routing lookup. It selects one usable ECMP hop, prefers IPv4 when IPv4/IPv6 defaults differ, and never silently falls back to aggregation. Other supported platforms retain manual/legacy modes and show an explicit automatic-detection error. Docker observes its own network namespace; host-wide visibility requires sharing the host namespace. No monitoring-specific capabilities, firewall changes, shell commands, Python, or extra daemon are introduced.
Totals are cumulative kernel counters, not monthly billing. Previous history remains intact when the selection changes. Physical Azure/SR-IOV hardware was unavailable locally; the double-counting regression uses deterministic counters. Separate IPv4/IPv6 traffic accounting is intentionally outside this PR.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.