Skip to content

feat(status): write per-user stats to a textfile (#1) - #11

Merged
mrcsin merged 1 commit into
masterfrom
status-metrics
Oct 27, 2026
Merged

mrcsin merged 1 commit into
masterfrom
status-metrics

Conversation

@mrcsin

@mrcsin mrcsin commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Problem

usher had no way to show which users connect and how much traffic they move. awg-grpc and Xray report it, but only usher maps a key or an email to a user name. Issue #1 covered AmneziaWG only; the Xray backend landed after it.

Change

  • Each pass writes <USHER_STATUS_DIR>/usher.prom in Prometheus text format for node_exporter's textfile collector. Unset USHER_STATUS_DIR keeps the old behaviour.
  • One metric set for both backends, labelled {interface, user}: usher_interface_up, usher_user_online, usher_user_uplink_bytes_total, usher_user_downlink_bytes_total.
  • Session.Stats: AWG maps ListPeers (online = handshake under 180 s); Xray maps QueryStats and GetAllOnlineUsers.
  • A stats error drops that interface's users from the file and never fails the interface. usher checks the Xray config for the stats switches and logs the missing ones instead of writing zeros.

Differences from the issue: Xray is covered; "connected" is computed by usher (usher_user_online) instead of a PromQL query, because Xray has no handshake time; there is no handshake or pass-timestamp metric (last seen comes from the history of usher_user_online, staleness from node_textfile_mtime_seconds); the file is written through the existing atomicfile.Write; the directory is opt-in by env, not probed.

Semantics per backend are in the README ## Stats section and docs/xray.md.

Verification

  • go test -race ./... and scripts/format.sh pass locally.
  • Both e2e suites gain a stats step; they have not run outside CI yet, so this PR's e2e job is their first run.

Closes #1

Per-task commits before collapse
4d5a85f docs(plans): drop server details from the plan
2277119 docs(plans): record the exec run and checks
e8c9999 refactor(repo): drop comments that restate code
02454d1 refactor(repo): address smell findings
96de663 fix(repo): address review findings
2240f6b docs(stats): describe the status file and its setup
6f3bb46 fix(pass): write a shared interface name once
fd09bc6 test(e2e): assert the status file in both suites
1eb2270 feat(usher): add USHER_STATUS_DIR and status mount
a144fd9 feat(pass): write the status file after apply
f59f9ed feat(xray): read per-user stats from StatsService
daa852f feat(xray): report missing stats switches in config
e107be2 refactor(xray): dial handler and stats clients together
2a37b8c feat(awg): read per-user stats from ListPeers
dd2e249 feat(status): add the exposition file renderer
67d2319 docs(plans): add user stats textfile plan (#1)

usher had no way to show which users connect and how much traffic they
move. awg-grpc and Xray both report it, but only usher maps a key or an
email to a user name.

Each pass now writes a Prometheus text exposition file that the
node_exporter textfile collector serves, so usher keeps no listener.
The file is backend-neutral: AmneziaWG and Xray users get the same
four metrics, usher_interface_up, usher_user_online and the uplink and
downlink byte counters, labelled by user and interface. Session gains
Stats; AWG maps ListPeers, with online as a handshake under 180 s, and
Xray maps StatsService counters and GetAllOnlineUsers.

Metrics are a side channel: a stats error drops that interface's users
from the file and never fails the interface or blocks reconcile. usher
checks the Xray config for the stats switches and logs the missing ones
instead of writing zeros. USHER_STATUS_DIR turns the file on; unset,
usher behaves as before.
@mrcsin
mrcsin marked this pull request as ready for review October 27, 2026 14:30
@mrcsin
mrcsin merged commit 9e8f0d2 into master Oct 27, 2026
2 checks passed
@mrcsin
mrcsin deleted the status-metrics branch October 27, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(status): per-peer metrics in a Prometheus textfile

1 participant