[PR #7058] feat(traffic): support configurable external traffic inform interval (#7028) #6625

Open
opened 2026-11-07 14:34:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/7058
Author: @DoctorGuidance
Created: 11/3/2026
Status: 🔄 Open

Base: main ← Head: feat/external-traffic-inform-interval


📝 Commits (1)

  • eeb3744 feat(traffic): support configurable external traffic inform interval (#7028)

📊 Changes

9 files changed (+196 additions, -9 deletions)

View changed files

📝 frontend/src/models/setting.ts (+1 -0)
📝 frontend/src/pages/settings/GeneralTab.tsx (+19 -0)
📝 frontend/src/schemas/setting.ts (+1 -0)
📝 internal/web/entity/entity.go (+8 -3)
📝 internal/web/job/xray_traffic_inform_test.go (+57 -0)
📝 internal/web/job/xray_traffic_job.go (+94 -3)
📝 internal/web/service/setting.go (+12 -3)
📝 internal/web/translation/en-US.json (+2 -0)
📝 internal/web/translation/fa-IR.json (+2 -0)

📄 Description

Summary

Fixes #7028.

Currently, the external traffic inform webhook (informTrafficToExternalAPI) triggers on every internal Xray traffic poll cycle (@every 5s). In multi-node panels or setups integrated with external billing/accounting systems, pushing HTTP webhooks every 5 seconds introduces unnecessary network pressure, HTTP connection churn, and excessive database write overhead on external accounting APIs.

This PR makes the external traffic inform interval configurable while ensuring zero traffic reporting is lost:

  1. Configurable Interval (externalTrafficInformInterval):

    • Added externalTrafficInformInterval setting (defaults to 5 seconds, minimum 5s).
    • Integrated into Settings -> General -> External Traffic tab with InputNumber and unit label.
    • Added translations in en-US.json and fa-IR.json.
  2. Accurate Delta Accumulation:

    • Inbound traffic deltas (xray.Traffic) and client traffic deltas (xray.ClientTraffic) are accumulated across intermediate 5-second polling ticks in thread-safe memory maps (accumInbounds and accumClients guarded by informMu sync.Mutex).
    • Accurately sums byte deltas (Up and Down) across cycles so no usage is missed.
    • Flushes accumulated traffic to the external webhook URI when the configured interval has elapsed, then safely resets the accumulation buffer.
    • If external traffic inform is toggled off, buffers are cleared immediately.
  3. Backward Compatibility:

    • Default interval remains 5 seconds, preserving identical behavior for existing configurations.

Verification

  • Added unit tests in internal/web/job/xray_traffic_inform_test.go testing multi-tick delta accumulation and buffer clearance.
  • Passed frontend typecheck (tsc --noEmit), linter (oxlint), and formatter (oxfmt).
  • Verified setting entity validation in internal/web/entity.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/7058 **Author:** [@DoctorGuidance](https://github.com/DoctorGuidance) **Created:** 11/3/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/external-traffic-inform-interval` --- ### 📝 Commits (1) - [`eeb3744`](https://github.com/MHSanaei/3x-ui/commit/eeb374443f3dc1896f0f2d203bc8e39fde296db4) feat(traffic): support configurable external traffic inform interval (#7028) ### 📊 Changes **9 files changed** (+196 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/models/setting.ts` (+1 -0) 📝 `frontend/src/pages/settings/GeneralTab.tsx` (+19 -0) 📝 `frontend/src/schemas/setting.ts` (+1 -0) 📝 `internal/web/entity/entity.go` (+8 -3) 📝 `internal/web/job/xray_traffic_inform_test.go` (+57 -0) 📝 `internal/web/job/xray_traffic_job.go` (+94 -3) 📝 `internal/web/service/setting.go` (+12 -3) 📝 `internal/web/translation/en-US.json` (+2 -0) 📝 `internal/web/translation/fa-IR.json` (+2 -0) </details> ### 📄 Description ### Summary Fixes #7028. Currently, the external traffic inform webhook (`informTrafficToExternalAPI`) triggers on every internal Xray traffic poll cycle (`@every 5s`). In multi-node panels or setups integrated with external billing/accounting systems, pushing HTTP webhooks every 5 seconds introduces unnecessary network pressure, HTTP connection churn, and excessive database write overhead on external accounting APIs. This PR makes the external traffic inform interval configurable while ensuring **zero traffic reporting is lost**: 1. **Configurable Interval (`externalTrafficInformInterval`)**: - Added `externalTrafficInformInterval` setting (defaults to `5` seconds, minimum `5s`). - Integrated into Settings -> General -> External Traffic tab with `InputNumber` and unit label. - Added translations in `en-US.json` and `fa-IR.json`. 2. **Accurate Delta Accumulation**: - Inbound traffic deltas (`xray.Traffic`) and client traffic deltas (`xray.ClientTraffic`) are accumulated across intermediate 5-second polling ticks in thread-safe memory maps (`accumInbounds` and `accumClients` guarded by `informMu sync.Mutex`). - Accurately sums byte deltas (`Up` and `Down`) across cycles so no usage is missed. - Flushes accumulated traffic to the external webhook URI when the configured interval has elapsed, then safely resets the accumulation buffer. - If external traffic inform is toggled off, buffers are cleared immediately. 3. **Backward Compatibility**: - Default interval remains 5 seconds, preserving identical behavior for existing configurations. ### Verification - Added unit tests in `internal/web/job/xray_traffic_inform_test.go` testing multi-tick delta accumulation and buffer clearance. - Passed frontend typecheck (`tsc --noEmit`), linter (`oxlint`), and formatter (`oxfmt`). - Verified setting entity validation in `internal/web/entity`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#6625
No description provided.