Files
nginx-ui/internal/nginx_log/analytics
0xJacky 44fc6ea425 feat(nginx_log): add site traffic and QPS statistics
Closes #1498.

Report per-site total requests, total traffic and QPS, and add a quick
switch for enabling a site's access log.

Traffic totals were previously extrapolated from the average bytes of the
50 rows on the current page, so the figure moved as you paged. The cause
was that SearchRequest.IncludeStats was declared but never implemented,
leaving SearchResult.Stats nil. Bleve has no sum aggregation, so the new
searcher stats pass walks the match set with a SearchAfter cursor loading
only bytes_sent and request_time. The scan is capped at 200k documents;
past that it extrapolates from the scanned prefix and reports Approximate
so the UI can mark the value. Results are cached under a key that strips
pagination and sorting, since the aggregation describes the whole match
set rather than one page.

The dashboard summary gains total_traffic, avg_qps and peak_qps. These
ride along with the scan that already fills the hourly and daily buckets,
so no extra query is needed. Peak QPS comes from per-minute buckets
rather than the existing hourly ones, which would flatten a real peak.

The Access Log switch writes or removes the access_log directive for the
current server, with a path proposed from the new default_log_dir
endpoint, so enabling per-site logging no longer means typing the
directive by hand. A site declaring no directive inherits the shared
default log, whose traffic belongs to every other site too. The switch is
offered for http servers only, as the log viewer and indexer parse http
access log formats. "access_log off;" now reads as off rather than as a
log named "off".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 09:12:18 +08:00
..