[GH-ISSUE #6906] [Feature]: Traffic statistics can be configured to select the network interface card #4578

Open
opened 2026-10-31 20:40:38 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @zyxwhj7777-png on GitHub (Oct 23, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6906

The sent and received traffic on the network card in the system status doesn't match the cloud provider's traffic statistics. When 3x-ui's 'System Status' summarises network card traffic, it probably just adds up the traffic of all non-loopback interfaces in /proc/net/dev. This way, your actual proxy traffic (like about 30GB) gets counted once for eth0 and once for enP6129s1, so the total naturally becomes about 60GB, exactly double the client traffic.

Image Image Image

Describe the solution you'd like

In the panel settings, you can select the network interface used for traffic statistics

Alternatives you've considered

No response

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

Statistics / traffic counters

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @zyxwhj7777-png on GitHub (Oct 23, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6906 ### Is your feature request related to a problem? The sent and received traffic on the network card in the system status doesn't match the cloud provider's traffic statistics. When 3x-ui's 'System Status' summarises network card traffic, it probably just adds up the traffic of all non-loopback interfaces in /proc/net/dev. This way, your actual proxy traffic (like about 30GB) gets counted once for eth0 and once for enP6129s1, so the total naturally becomes about 60GB, exactly double the client traffic. <img width="746" height="26" alt="Image" src="https://github.com/user-attachments/assets/ba6b1416-fee4-4bf2-a0fb-61ab7b062168" /> <img width="811" height="74" alt="Image" src="https://github.com/user-attachments/assets/80efdfc4-29d8-4825-91b0-a9753c4a3623" /> <img width="793" height="279" alt="Image" src="https://github.com/user-attachments/assets/d7533899-c3f9-42a9-92b4-cc8eb13ba14e" /> ### Describe the solution you'd like In the panel settings, you can select the network interface used for traffic statistics ### Alternatives you've considered _No response_ ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? Statistics / traffic counters ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 23, 2026):

Your reading of the code is right: the panel has no setting to choose an interface. The "System Status" network totals add up every interface that is not on a hard-coded list of virtual names, and enP6129s1 is not on that list. Being able to pick the interface is a reasonable feature request.

How the totals are built (internal/web/service/server.go:637-655):

ioStats, err := net.IOCounters(true)
...
for _, iface := range ioStats {
    name := strings.ToLower(iface.Name)
    if isVirtualInterface(name) {
        continue
    }
    totalSent += iface.BytesSent
    totalRecv += iface.BytesRecv

isVirtualInterface (internal/web/service/server.go:1498-1522) only skips lo/lo0 and names that start with loopback, docker, br-, veth, virbr, tun, tap, wg, tailscale or zt. Every other interface gets added to the total. The same NetTraffic totals also feed the Telegram report (internal/web/service/tgbot/tgbot_report.go:156) and the Discord report (internal/web/service/discord/report.go:111-113), so those reports show the doubled figure too. This filter came in with commit ad302987 ("Exclude virtual interfaces from network stats"). It has no tests, and I found no other setting that changes it.

Why the total is doubled on your server (my inference, not confirmed in this repo): names like enP<n>s<n> are what Azure's Accelerated Networking gives the SR-IOV virtual function. That function is attached as a secondary device under the synthetic eth0, and the kernel's eth0 counters already include the traffic that goes through it. Adding both interfaces counts the same bytes twice. You can check this on your server:

ip -d link show enP6129s1   # "master eth0" in the output means it is attached to eth0
cat /proc/net/dev

If it shows master eth0, the panel is double-counting. The same thing would happen with other stacked setups the prefix list doesn't catch, such as bond member interfaces (counted under the bond as well) or VLAN sub-interfaces.

Two other differences from your cloud provider's numbers come from how the counters work, so even a single-interface option would not remove them:

  • The counters are cumulative since boot. They are not a monthly or billing-period total.
  • Many providers only bill outbound traffic, while the panel shows sent and received separately.

The data needed for your idea is already there: net.IOCounters(true) returns per-interface counters, so an "interface for traffic statistics" setting would just restrict the existing loop. Skipping any interface that has a master device would also fix this case automatically, without the user setting anything. I couldn't open your screenshots, but the explanation above doesn't depend on them. I found no earlier issue asking for this.

Verdict: Feature request

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:6358366425 --> @github-actions[bot] commented on GitHub (Oct 23, 2026): Your reading of the code is right: the panel has no setting to choose an interface. The "System Status" network totals add up every interface that is not on a hard-coded list of virtual names, and `enP6129s1` is not on that list. Being able to pick the interface is a reasonable feature request. **How the totals are built** (`internal/web/service/server.go:637-655`): ```go ioStats, err := net.IOCounters(true) ... for _, iface := range ioStats { name := strings.ToLower(iface.Name) if isVirtualInterface(name) { continue } totalSent += iface.BytesSent totalRecv += iface.BytesRecv ``` `isVirtualInterface` (`internal/web/service/server.go:1498-1522`) only skips `lo`/`lo0` and names that start with `loopback`, `docker`, `br-`, `veth`, `virbr`, `tun`, `tap`, `wg`, `tailscale` or `zt`. Every other interface gets added to the total. The same `NetTraffic` totals also feed the Telegram report (`internal/web/service/tgbot/tgbot_report.go:156`) and the Discord report (`internal/web/service/discord/report.go:111-113`), so those reports show the doubled figure too. This filter came in with commit `ad302987` ("Exclude virtual interfaces from network stats"). It has no tests, and I found no other setting that changes it. **Why the total is doubled on your server (my inference, not confirmed in this repo):** names like `enP<n>s<n>` are what Azure's Accelerated Networking gives the SR-IOV virtual function. That function is attached as a secondary device under the synthetic `eth0`, and the kernel's `eth0` counters already include the traffic that goes through it. Adding both interfaces counts the same bytes twice. You can check this on your server: ```sh ip -d link show enP6129s1 # "master eth0" in the output means it is attached to eth0 cat /proc/net/dev ``` If it shows `master eth0`, the panel is double-counting. The same thing would happen with other stacked setups the prefix list doesn't catch, such as bond member interfaces (counted under the bond as well) or VLAN sub-interfaces. Two other differences from your cloud provider's numbers come from how the counters work, so even a single-interface option would not remove them: - The counters are cumulative since boot. They are not a monthly or billing-period total. - Many providers only bill outbound traffic, while the panel shows sent and received separately. The data needed for your idea is already there: `net.IOCounters(true)` returns per-interface counters, so an "interface for traffic statistics" setting would just restrict the existing loop. Skipping any interface that has a master device would also fix this case automatically, without the user setting anything. I couldn't open your screenshots, but the explanation above doesn't depend on them. I found no earlier issue asking for this. Verdict: Feature request *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@HamedSanaei commented on GitHub (Oct 27, 2026):

I've implemented a proposed solution for this feature request.

The PR adds configurable network interface selection for system traffic statistics:

  • Legacy aggregation for backward compatibility.
  • Automatic selection using the default network route.
  • Manual selection of a specific network interface.

This allows users with stacked network interfaces (including Azure Accelerated Networking setups) to avoid double-counting by monitoring the appropriate interface.

The implementation also handles counter discontinuities when interfaces change or counters reset, and includes regression tests.

The automatic selection approach was inspired by my existing IPv6Monitor project:
https://github.com/HamedSanaei/ipv6monitor

PR: https://github.com/MHSanaei/3x-ui/pull/6972

Feedback and testing on affected systems are welcome.

<!-- gh-comment-id:6433401024 --> @HamedSanaei commented on GitHub (Oct 27, 2026): I've implemented a proposed solution for this feature request. The PR adds configurable network interface selection for system traffic statistics: - Legacy aggregation for backward compatibility. - Automatic selection using the default network route. - Manual selection of a specific network interface. This allows users with stacked network interfaces (including Azure Accelerated Networking setups) to avoid double-counting by monitoring the appropriate interface. The implementation also handles counter discontinuities when interfaces change or counters reset, and includes regression tests. The automatic selection approach was inspired by my existing IPv6Monitor project: https://github.com/HamedSanaei/ipv6monitor PR: https://github.com/MHSanaei/3x-ui/pull/6972 Feedback and testing on affected systems are welcome.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4578
No description provided.