[GH-ISSUE #6934] [Feature]: Expose AmneziaWG/WireGuard peer handshake time and per-peer traffic via API #4586

Closed
opened 2026-10-31 20:40:42 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @MaxRink on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6934

With the built-in AmneziaWG inbound (v3.10.2, Docker), there is no way to see whether a peer is actually connected. The panel and API return per-inbound traffic, but there is no last-handshake time and no traffic counters per peer. AWG traffic also reaches Xray without a client email, so the per-client stats stay empty for AWG peers. Because the AWG device runs inside the panel process, awg show / wg show are not available in the container to read this from outside.

Describe the solution you'd like

Add the per-peer runtime state the WireGuard/AmneziaWG device already tracks to the inbound API:

  • lastHandshake (unix seconds, 0 if never)
  • rx / tx bytes
  • the current endpoint (optional)

It could go in the existing GET /panel/api/inbounds/get/:id (or list) response as a peerStats array keyed by peer public key or peer name, or in a separate endpoint such as GET /panel/api/inbounds/:id/peers. Showing "last handshake N min ago" next to each peer in the inbound UI would be a nice extra.

Alternatives you've considered

  • awg show dump from the host or container: there is no kernel or awg-go device visible outside the panel process.
  • Using the per-inbound traffic as a proxy: this only works with one peer per inbound, and it does not show whether the peer is connected right now.
  • Xray per-client stats: AWG peers have no client email, so these stay empty.

Concrete use case

I monitor a small AmneziaWG inbound (a few peers, one per device, including a travel router) with Prometheus. I want to alert when a peer has not completed a handshake for longer than X minutes while it should be online, and to graph per-device traffic. Today I can only see bytes per inbound.

Which parts of the panel would this affect?

Backend (API endpoints, login, settings); Statistics / traffic counters; Frontend (UI / panel pages)

Are you willing to help?

  • 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 @MaxRink on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6934 ### Is your feature request related to a problem? With the built-in AmneziaWG inbound (v3.10.2, Docker), there is no way to see whether a peer is actually connected. The panel and API return per-inbound traffic, but there is no last-handshake time and no traffic counters per peer. AWG traffic also reaches Xray without a client email, so the per-client stats stay empty for AWG peers. Because the AWG device runs inside the panel process, `awg show` / `wg show` are not available in the container to read this from outside. ### Describe the solution you'd like Add the per-peer runtime state the WireGuard/AmneziaWG device already tracks to the inbound API: - `lastHandshake` (unix seconds, 0 if never) - `rx` / `tx` bytes - the current `endpoint` (optional) It could go in the existing `GET /panel/api/inbounds/get/:id` (or `list`) response as a `peerStats` array keyed by peer public key or peer name, or in a separate endpoint such as `GET /panel/api/inbounds/:id/peers`. Showing "last handshake N min ago" next to each peer in the inbound UI would be a nice extra. ### Alternatives you've considered - `awg show dump` from the host or container: there is no kernel or awg-go device visible outside the panel process. - Using the per-inbound traffic as a proxy: this only works with one peer per inbound, and it does not show whether the peer is connected right now. - Xray per-client stats: AWG peers have no client email, so these stay empty. ### Concrete use case I monitor a small AmneziaWG inbound (a few peers, one per device, including a travel router) with Prometheus. I want to alert when a peer has not completed a handshake for longer than X minutes while it should be online, and to graph per-device traffic. Today I can only see bytes per inbound. ### Which parts of the panel would this affect? Backend (API endpoints, login, settings); Statistics / traffic counters; Frontend (UI / panel pages) ### Are you willing to help? - [x] I can help test once a PR is open. ### Before submitting - [x] I searched existing issues and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:40:42 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 25, 2026):

Most of this already exists in v3.10.2. The panel reads each AmneziaWG peer's last handshake, rx/tx bytes, endpoint and allowed IPs from the embedded device, and serves them on POST /panel/api/server/amneziawglogs/:count. That endpoint is server-wide, not per inbound, which is the only part of your request that is still missing.

What you can use today

The endpoint was added in effcccce (feat(amneziawg): add native AmneziaWG protocol support (#6105)) and is in the v3.10.0 and v3.10.2 tags. It is registered at internal/web/controller/server.go:79:

g.POST("/amneziawglogs/:count", a.getAmneziaWGLogs)

It sits under the /panel/api group, so an API token works (Authorization: Bearer ..., internal/web/controller/api.go:46):

curl -s -X POST -H "Authorization: Bearer <token>" \
  --data-urlencode "filter=" \
  https://<panel>/<basepath>/panel/api/server/amneziawglogs/1000

Each item in obj.peers is a PeerActivity (internal/web/service/server.go:1331-1343):

field meaning
inboundId, tag, interface which inbound the peer belongs to
email the client the peer is configured as
endpoint, allowedIPs current endpoint and allowed IPs from the live device
handshake last handshake in unix milliseconds (not seconds), 0 if the peer never connected
up / down the device's rx_bytes / tx_bytes for that peer (server.go:1418-1419)
online true when the last handshake is under 180 s old (amneziawgOnlineWindow = 180 * time.Second, server.go:1348)

The :count parameter caps how many rows come back: values outside 1–10000 fall back to 100 (server.go:1438-1440). The optional filter form field is a case-insensitive substring match on email, tag, interface, endpoint and allowed IPs, so filter=<inbound tag> narrows the result to one inbound. In the UI, the same data is in the AmneziaWG log view on the Overview page (frontend/src/pages/index/AmneziaWGLogModal.tsx). For your Prometheus alert, now_ms - handshake > X*60000 on each email should work. The rx/tx values are the live device counters, so they start from zero again whenever the interface is recreated.

There are two limits. Inbounds hosted on a node are skipped (node_id IS NULL in the query at server.go:1386). The opt-in kernel datapath (56ac8d0f, not yet in a release) is a separate path, so this does not apply to it.

On "AWG peers have no client email"

The source does not match this. Decrypted AmneziaWG traffic goes into a loopback Xray SOCKS5 inbound and logs in with the peer's own client email as the username (internal/amneziawgnet/relay.go:1-6, manager.go:221 relay.RelayTCP(conn, peer.Email, dest)). The accounts for that inbound are built from the peers' emails (internal/web/service/xray.go:803-813). So per-client Xray stats should fill in for AWG clients, with one designed exception: port-forwarded bytes skip Xray (internal/amneziawgnet/portfwd.go:17). If a normal, non-port-forwarded AWG client's up/down really stays at 0 in the client list on v3.10.2, please open a separate bug report with the client's JSON and the inbound's settings. I can't check that path without them.

What is still a feature request

There is a per-inbound service method, InboundService.GetAmneziaWGDiagnostics(id) (internal/web/service/inbound_amneziawg.go:453), but no route uses it. A GET /panel/api/inbounds/:id/peers-style endpoint, or a per-peer "last handshake" column in the inbound's client list, would need new wiring. The underlying data is already collected by amneziawgnet.Diagnose (internal/amneziawgnet/diagnostics.go:50).

No existing issue asks for this; none of the AmneziaWG issues I found (#6319, #6378, #6774) cover it.

Verdict: Feature request. Per-peer handshake and traffic are already exposed server-wide via /panel/api/server/amneziawglogs/:count in v3.10.2; a per-inbound endpoint and an inline UI column are not.

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

<!-- gh-comment-id:6399351686 --> @github-actions[bot] commented on GitHub (Oct 25, 2026): Most of this already exists in v3.10.2. The panel reads each AmneziaWG peer's last handshake, rx/tx bytes, endpoint and allowed IPs from the embedded device, and serves them on `POST /panel/api/server/amneziawglogs/:count`. That endpoint is server-wide, not per inbound, which is the only part of your request that is still missing. **What you can use today** The endpoint was added in effcccce (`feat(amneziawg): add native AmneziaWG protocol support (#6105)`) and is in the v3.10.0 and v3.10.2 tags. It is registered at `internal/web/controller/server.go:79`: ```go g.POST("/amneziawglogs/:count", a.getAmneziaWGLogs) ``` It sits under the `/panel/api` group, so an API token works (`Authorization: Bearer ...`, `internal/web/controller/api.go:46`): ```bash curl -s -X POST -H "Authorization: Bearer <token>" \ --data-urlencode "filter=" \ https://<panel>/<basepath>/panel/api/server/amneziawglogs/1000 ``` Each item in `obj.peers` is a `PeerActivity` (`internal/web/service/server.go:1331-1343`): | field | meaning | |---|---| | `inboundId`, `tag`, `interface` | which inbound the peer belongs to | | `email` | the client the peer is configured as | | `endpoint`, `allowedIPs` | current endpoint and allowed IPs from the live device | | `handshake` | last handshake in **unix milliseconds** (not seconds), `0` if the peer never connected | | `up` / `down` | the device's `rx_bytes` / `tx_bytes` for that peer (`server.go:1418-1419`) | | `online` | `true` when the last handshake is under 180 s old (`amneziawgOnlineWindow = 180 * time.Second`, `server.go:1348`) | The `:count` parameter caps how many rows come back: values outside 1–10000 fall back to 100 (`server.go:1438-1440`). The optional `filter` form field is a case-insensitive substring match on email, tag, interface, endpoint and allowed IPs, so `filter=<inbound tag>` narrows the result to one inbound. In the UI, the same data is in the AmneziaWG log view on the Overview page (`frontend/src/pages/index/AmneziaWGLogModal.tsx`). For your Prometheus alert, `now_ms - handshake > X*60000` on each `email` should work. The rx/tx values are the live device counters, so they start from zero again whenever the interface is recreated. There are two limits. Inbounds hosted on a node are skipped (`node_id IS NULL` in the query at `server.go:1386`). The opt-in kernel datapath (56ac8d0f, not yet in a release) is a separate path, so this does not apply to it. **On "AWG peers have no client email"** The source does not match this. Decrypted AmneziaWG traffic goes into a loopback Xray SOCKS5 inbound and logs in with the peer's own client email as the username (`internal/amneziawgnet/relay.go:1-6`, `manager.go:221` `relay.RelayTCP(conn, peer.Email, dest)`). The accounts for that inbound are built from the peers' emails (`internal/web/service/xray.go:803-813`). So per-client Xray stats should fill in for AWG clients, with one designed exception: port-forwarded bytes skip Xray (`internal/amneziawgnet/portfwd.go:17`). If a normal, non-port-forwarded AWG client's up/down really stays at 0 in the client list on v3.10.2, please open a separate bug report with the client's JSON and the inbound's `settings`. I can't check that path without them. **What is still a feature request** There is a per-inbound service method, `InboundService.GetAmneziaWGDiagnostics(id)` (`internal/web/service/inbound_amneziawg.go:453`), but no route uses it. A `GET /panel/api/inbounds/:id/peers`-style endpoint, or a per-peer "last handshake" column in the inbound's client list, would need new wiring. The underlying data is already collected by `amneziawgnet.Diagnose` (`internal/amneziawgnet/diagnostics.go:50`). No existing issue asks for this; none of the AmneziaWG issues I found (#6319, #6378, #6774) cover it. Verdict: Feature request. Per-peer handshake and traffic are already exposed server-wide via `/panel/api/server/amneziawglogs/:count` in v3.10.2; a per-inbound endpoint and an inline UI column are not. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@MaxRink commented on GitHub (Oct 25, 2026):

Thanks a lot for the detailed analysis, that was exactly the missing piece.

I verified POST /panel/api/server/amneziawglogs/:count on v3.10.2 (Docker) with an API token: obj.peers[] has email, tag, interface, handshake (ms), up/down and online as you described. I now scrape it into Prometheus (per-peer last handshake, rx/tx and online) and alert when a peer that was connected in the last 24 h has had no handshake for 30 minutes, so the server-wide endpoint covers my monitoring need.

I also confirmed the AmneziaWG flows enter the loopback SOCKS inbound with the peer's email as the user, so my statement about missing client emails was wrong; sorry about that. I have not seen a non-port-forwarded client stay at zero, so there is no bug to report for now.

From my side this can be closed as answered. A per-inbound endpoint (GetAmneziaWGDiagnostics) or a "last handshake" column in the inbound client list would still be a nice extra, but I don't need it; feel free to keep it open for that or close it.

<!-- gh-comment-id:6400822531 --> @MaxRink commented on GitHub (Oct 25, 2026): Thanks a lot for the detailed analysis, that was exactly the missing piece. I verified `POST /panel/api/server/amneziawglogs/:count` on v3.10.2 (Docker) with an API token: `obj.peers[]` has `email`, `tag`, `interface`, `handshake` (ms), `up`/`down` and `online` as you described. I now scrape it into Prometheus (per-peer last handshake, rx/tx and online) and alert when a peer that was connected in the last 24 h has had no handshake for 30 minutes, so the server-wide endpoint covers my monitoring need. I also confirmed the AmneziaWG flows enter the loopback SOCKS inbound with the peer's email as the user, so my statement about missing client emails was wrong; sorry about that. I have not seen a non-port-forwarded client stay at zero, so there is no bug to report for now. From my side this can be closed as answered. A per-inbound endpoint (`GetAmneziaWGDiagnostics`) or a "last handshake" column in the inbound client list would still be a nice extra, but I don't need it; feel free to keep it open for that or close it.
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#4586
No description provided.