[GH-ISSUE #6353] [Feature]: Traffic Usage History by Custom Date Range #4310

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

Originally created by @zulfiqar-shaloom on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6353

Currently, 3X-UI only shows the current/total traffic usage for clients. There is no easy way to check how much traffic a specific client, or all clients combined, used during a specific period such as the last 7 days, last 30 days, or between two custom dates.

Describe the solution you'd like

I would like 3X-UI to store historical traffic usage statistics for each client.

It would be useful to have a traffic statistics page where we can:

View upload, download, and total usage for each client.
View the combined traffic usage of all clients.
Select preset periods such as Today, Last 7 Days, and Last 30 Days.
Select a custom date range (From / To).
Optionally view daily traffic usage and sort clients by highest usage.

Ideally, these statistics should remain available even when the client's traffic counter is reset.

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?

No response

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 @zulfiqar-shaloom on GitHub (Aug 28, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6353 ### Is your feature request related to a problem? Currently, 3X-UI only shows the current/total traffic usage for clients. There is no easy way to check how much traffic a specific client, or all clients combined, used during a specific period such as the last 7 days, last 30 days, or between two custom dates. ### Describe the solution you'd like I would like 3X-UI to store historical traffic usage statistics for each client. It would be useful to have a traffic statistics page where we can: View upload, download, and total usage for each client. View the combined traffic usage of all clients. Select preset periods such as Today, Last 7 Days, and Last 30 Days. Select a custom date range (From / To). Optionally view daily traffic usage and sort clients by highest usage. Ideally, these statistics should remain available even when the client's traffic counter is reset. ### 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? _No response_ ### 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 - [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 (Aug 28, 2026):

This is a valid feature request, and none of it exists at the tip (latest release v3.7.0): the panel stores no traffic history at all today, so there is nothing that could be sliced by a date range yet.

What the source says

Per-client usage is one row per client in client_traffics, holding two cumulative counters and no time dimension — internal/xray/client_traffic.go:12-13:

Up         int64  `json:"up" form:"up" example:"1048576"`
Down       int64  `json:"down" form:"down" example:"2097152"`

allModels() (internal/database/db.go:65-88) lists every table the panel creates, and there is no per-day/per-period traffic table among them.

A reset overwrites those two counters in place; nothing is archived first — internal/web/service/inbound_traffic.go:628-631:

if err := tx.Model(xray.ClientTraffic{}).
	Where("email = ?", clientEmail).
	Updates(map[string]any{"enable": true, "up": 0, "down": 0}).Error; err != nil {

The only time series the panel keeps is whole-host system metrics (CPU / memory / network), in an in-memory rollup ladder capped at 7 days — internal/web/service/metric_history.go:33-37:

var metricTiers = []tierSpec{
	{resolution: 2, capacity: 1800},   // 1h at 2s
	{resolution: 60, capacity: 2880},  // 48h at 1m
	{resolution: 600, capacity: 1008}, // 7d at 10m
}

That series is host-wide and never per-client, so it cannot answer "how much did client X use last week".

What already works today

One item on your list is done: sorting clients by usage — but of the current counters, not of a date range. Route internal/web/controller/client.go:49, sort key handled at internal/web/service/client_paging.go:316:

curl -H "Authorization: Bearer <token>" \
  "https://<panel-host>/<base-path>/panel/api/clients/list/paged?sort=traffic&order=descend"

Per-client counters for a single client come from GET /panel/api/clients/traffic/:email (internal/web/controller/client.go:52), and GET /panel/api/inbounds/list returns each inbound's clientStats. The token comes from Settings → Security → API Token (docs/content/docs/en/reference/api/authentication.mdx:5).

Until the panel stores history, a date range has to be reconstructed outside it: poll one of those endpoints on a cron, store (email, timestamp, up, down) yourself, and difference consecutive samples. One caveat that will otherwise corrupt your totals — because a reset zeroes up/down in place (the code above), a sample lower than the previous one means a new cycle started, so count the full new value as the delta instead of a negative.

Prior discussion worth reading

The "statistics survive a reset" half of this request has history: in #4532 the repository owner answered "All time traffic? Yes, i removed it on purpose", and #4756, which asked for that column back, was closed as a duplicate of it. I am deliberately not closing this as a duplicate — those two ask for a single cumulative all-time number, while you are asking for a per-period store queryable by date, which is a different data model — but the survives-reset part does restate a decision that was already made once, so that piece is the maintainer's call rather than an oversight.

#4947 (labelled backlog) overlaps from the other side: a per-client daily fair-usage limit needs the same per-day baseline you are asking to expose, so both would likely be served by one storage change.

Verdict: Feature request

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

<!-- gh-comment-id:5457690023 --> @github-actions[bot] commented on GitHub (Aug 28, 2026): This is a valid feature request, and none of it exists at the tip (latest release `v3.7.0`): the panel stores **no** traffic history at all today, so there is nothing that could be sliced by a date range yet. ## What the source says Per-client usage is one row per client in `client_traffics`, holding two cumulative counters and no time dimension — `internal/xray/client_traffic.go:12-13`: ```go Up int64 `json:"up" form:"up" example:"1048576"` Down int64 `json:"down" form:"down" example:"2097152"` ``` `allModels()` (`internal/database/db.go:65-88`) lists every table the panel creates, and there is no per-day/per-period traffic table among them. A reset overwrites those two counters in place; nothing is archived first — `internal/web/service/inbound_traffic.go:628-631`: ```go if err := tx.Model(xray.ClientTraffic{}). Where("email = ?", clientEmail). Updates(map[string]any{"enable": true, "up": 0, "down": 0}).Error; err != nil { ``` The only time series the panel keeps is whole-host system metrics (CPU / memory / network), in an in-memory rollup ladder capped at 7 days — `internal/web/service/metric_history.go:33-37`: ```go var metricTiers = []tierSpec{ {resolution: 2, capacity: 1800}, // 1h at 2s {resolution: 60, capacity: 2880}, // 48h at 1m {resolution: 600, capacity: 1008}, // 7d at 10m } ``` That series is host-wide and never per-client, so it cannot answer "how much did client X use last week". ## What already works today One item on your list is done: sorting clients by usage — but of the *current* counters, not of a date range. Route `internal/web/controller/client.go:49`, sort key handled at `internal/web/service/client_paging.go:316`: ```bash curl -H "Authorization: Bearer <token>" \ "https://<panel-host>/<base-path>/panel/api/clients/list/paged?sort=traffic&order=descend" ``` Per-client counters for a single client come from `GET /panel/api/clients/traffic/:email` (`internal/web/controller/client.go:52`), and `GET /panel/api/inbounds/list` returns each inbound's `clientStats`. The token comes from **Settings → Security → API Token** (`docs/content/docs/en/reference/api/authentication.mdx:5`). Until the panel stores history, a date range has to be reconstructed outside it: poll one of those endpoints on a cron, store `(email, timestamp, up, down)` yourself, and difference consecutive samples. One caveat that will otherwise corrupt your totals — because a reset zeroes `up`/`down` in place (the code above), a sample *lower* than the previous one means a new cycle started, so count the full new value as the delta instead of a negative. ## Prior discussion worth reading The "statistics survive a reset" half of this request has history: in #4532 the repository owner answered "All time traffic? Yes, i removed it on purpose", and #4756, which asked for that column back, was closed as a duplicate of it. I am deliberately **not** closing this as a duplicate — those two ask for a single cumulative all-time number, while you are asking for a per-period store queryable by date, which is a different data model — but the survives-reset part does restate a decision that was already made once, so that piece is the maintainer's call rather than an oversight. #4947 (labelled `backlog`) overlaps from the other side: a per-client daily fair-usage limit needs the same per-day baseline you are asking to expose, so both would likely be served by one storage change. Verdict: Feature request *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@abolfazlakbarzadeh commented on GitHub (Oct 14, 2026):

I made a tool:
https://github.com/abolfazlakbarzadeh/3x-ui-traffic-monitor

<!-- gh-comment-id:6163210775 --> @abolfazlakbarzadeh commented on GitHub (Oct 14, 2026): I made a tool: https://github.com/abolfazlakbarzadeh/3x-ui-traffic-monitor
Author
Owner

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

@MHSanaei I recommend closing this issue as not planned.

I've used 3x-ui for about five years, and in my experience, a built-in historical traffic dashboard would not add enough practical value to the core panel to justify its ongoing maintenance and resource costs. It introduces additional database writes, storage growth, index/backup overhead, query CPU, and some memory usage—especially on large deployments and multi-node setups. I would rather keep 3x-ui focused on reliable traffic accounting and enforcement than add an optional reporting subsystem that every installation must carry.

If this feature were ever accepted, I would strongly recommend a minimal, opt-in implementation instead of collecting and persisting snapshots at the existing 5-second traffic-poll interval:

  • Store only daily per-client upload/download aggregates in one indexed history table, using a stable client identity and day as the unique key.
  • Reuse the existing durable traffic-accounting pipeline; process changed usage in batches with idempotent UPSERTs. Do not add per-client reads/writes to each 5-second poll or introduce Redis/a second database.
  • Atomically preserve unrecorded usage before every manual, scheduled, and renewal reset. A background snapshot alone is not sufficient: resets, crashes, and downtime can otherwise lose or double-count traffic.
  • Handle multi-node and cross-panel aggregation without counting the same bytes twice. Cover resets, client deletion/recreation, delayed node sync, and retry/replay behavior.
  • Keep it disabled by default, bound the reporting date range, enforce a configurable retention period (e.g. 90 days), prune in batches, and benchmark write amplification, CPU, memory, and database size on both SQLite and PostgreSQL.

Even with these safeguards, the added complexity and ongoing overhead remain real. The earlier decision to intentionally remove all-time traffic (#4532) is also worth considering, although this request is not exactly the same feature.

My recommendation is to close #6353 as not planned, unless there is clear maintainer demand and measured evidence that the benefits outweigh those costs. Anyone who specifically needs historical analytics could use an external monitoring/reporting tool instead.

<!-- gh-comment-id:6412620392 --> @HamedSanaei commented on GitHub (Oct 26, 2026): @MHSanaei I recommend closing this issue as **not planned**. I've used 3x-ui for about **five years**, and in my experience, a built-in historical traffic dashboard would not add enough practical value to the core panel to justify its ongoing maintenance and resource costs. It introduces additional database writes, storage growth, index/backup overhead, query CPU, and some memory usage—especially on large deployments and multi-node setups. I would rather keep 3x-ui focused on reliable traffic accounting and enforcement than add an optional reporting subsystem that every installation must carry. If this feature were ever accepted, I would strongly recommend a **minimal, opt-in implementation** instead of collecting and persisting snapshots at the existing 5-second traffic-poll interval: - Store only **daily per-client upload/download aggregates** in one indexed history table, using a stable client identity and day as the unique key. - Reuse the existing durable traffic-accounting pipeline; process changed usage in batches with idempotent UPSERTs. Do not add per-client reads/writes to each 5-second poll or introduce Redis/a second database. - **Atomically preserve unrecorded usage before every manual, scheduled, and renewal reset.** A background snapshot alone is not sufficient: resets, crashes, and downtime can otherwise lose or double-count traffic. - Handle **multi-node and cross-panel aggregation** without counting the same bytes twice. Cover resets, client deletion/recreation, delayed node sync, and retry/replay behavior. - Keep it disabled by default, bound the reporting date range, enforce a configurable retention period (e.g. 90 days), prune in batches, and benchmark write amplification, CPU, memory, and database size on both SQLite and PostgreSQL. Even with these safeguards, the added complexity and ongoing overhead remain real. The earlier decision to intentionally remove all-time traffic (#4532) is also worth considering, although this request is not exactly the same feature. **My recommendation is to close #6353 as not planned**, unless there is clear maintainer demand and measured evidence that the benefits outweigh those costs. Anyone who specifically needs historical analytics could use an external monitoring/reporting tool instead.
Author
Owner

@abolfazlakbarzadeh commented on GitHub (Oct 26, 2026):

If we have it as a optional feature that can be enabled/disabled based on user desire would be good, based on situation and infra, for example I'm using a paid traffic-based CDN for tunneling traffic to foreign server and for some users I wanna see how much traffic a user is consuming for example 1 day to 1 week, it can be upon to server admin to use this feature according to its DB/processing-load

<!-- gh-comment-id:6414366541 --> @abolfazlakbarzadeh commented on GitHub (Oct 26, 2026): If we have it as a optional feature that can be enabled/disabled based on user desire would be good, based on situation and infra, for example I'm using a paid traffic-based CDN for tunneling traffic to foreign server and for some users I wanna see how much traffic a user is consuming for example 1 day to 1 week, it can be upon to server admin to use this feature according to its DB/processing-load
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#4310
No description provided.