Repository navigation
Conversation
Record traffic grouped by destination host (falling back to the destination IP), split between proxied and direct connections, and expose it through two new controller endpoints. - sample active trackers every second and settle the remaining bytes in Manager.Leave so that short connections and their tails are not lost - keep minute buckets for 24h and daily buckets for the configured retention (30 days by default) - bound memory with an LRU-ish eviction when the host limit is reached - persist to traffic-stats.json periodically and on shutdown - GET /traffic/hosts: aggregate a time range, filter by domain (suffix/exact) and by proxy/direct, sort by total, limit with top - GET /traffic/hosts/check: compare session totals against the kernel counters for reconciliation The feature is disabled by default and enabled with profile.store-traffic-stats, so existing deployments are unaffected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The controller exposes traffic per connection, but nothing aggregates it by destination host over time. Closed connections disappear from snapshots, so external pollers both miss short connections and lose the tail of longer ones.
Related: #2478 (persistent per-client statistics), #3127 (report short-lived connections in snapshots).
Change
Manager.Leave, so short connections and their tails are accounted for exactly.traffic-stats-max-hostsis reached.traffic-stats.jsonperiodically and on shutdown, restoring on startup.GET /traffic/hosts?since=&until=&domain=&match=suffix|exact&group=proxy|direct|all&top=GET /traffic/hosts/check— session totals versus kernel counters, for reconciliationConfiguration
The feature is disabled by default, so existing deployments are unaffected. Both endpoints return 404 while it is disabled, and the existing
/connectionsresponse is unchanged.Testing
go test ./tunnel/statistic/covers first-sample accounting, delta sampling, close settlement, the proxy/direct split, suffix versus exact matching, time-range filtering, IP fallback, eviction, persistence round-trip and the disabled state./traffic/hosts/checkreports a stable zero delta between the aggregated statistics and the kernel counters, including across a 1.5 MB transfer.