Skip to content

Commit 1b507ae

Browse files
committed
ipn/wg: peer & dns resolution stats
1 parent 8316e1a commit 1b507ae

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

intra/backend/ipn_proxies.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ type RouterStats struct {
258258
Since int64
259259
// Current proxy status
260260
Status string
261+
// Extra is extra info about this router
262+
Extra string
261263
}
262264

263265
type RpnServers interface {

intra/ipn/multihost/map.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package multihost
88

99
import (
10+
"fmt"
1011
"net/netip"
1112
"net/url"
1213
"strings"
@@ -202,9 +203,12 @@ func (m *MHMap) String() string {
202203

203204
var sb strings.Builder
204205
sb.WriteString(m.k + ": ")
206+
i := 0
205207
for h := range m.uniq {
208+
sb.WriteString(fmt.Sprintf("#%d ", i))
206209
sb.WriteString(h.String())
207210
sb.WriteString(" / ")
211+
i++
208212
}
209213
return sb.String()
210214
}

intra/ipn/multihost/multihost.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,18 @@ func (h *MH) String() string {
7777
if h == nil {
7878
return "<nil>"
7979
}
80-
return h.o + ":" + strings.Join(h.straddrs(), ",")
80+
return h.o + "[" + strings.Join(h.Names(), ",") +
81+
" | " + strings.Join(h.straddrs(), ",") + "]" +
82+
" @ " + core.FmtTimeAsPeriod(h.Mtime())
83+
}
84+
85+
func (h *MH) Mtime() time.Time {
86+
if h == nil {
87+
return time.Time{}
88+
}
89+
h.RLock()
90+
defer h.RUnlock()
91+
return h.mtime
8192
}
8293

8394
func (h *MH) straddrs() []string {

intra/ipn/wgproxy.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,20 +1125,10 @@ func (tun *wgtun) Close() error {
11251125
func (w *wgproxy) Stat() (out *x.RouterStats) {
11261126
out = new(x.RouterStats)
11271127

1128-
if w.status.Load() == END {
1129-
log.W("proxy: wg: %s stats: stopped", w.tag())
1130-
return // zz
1131-
}
1132-
1133-
stat := wg.ReadStats(w.id, w.Handle(), w.Device.IpcGet)
1134-
if stat == nil { // unlikely
1135-
log.V("proxy: wg: %s stats: readstats: nil", w.tag())
1136-
return // zz
1137-
}
1138-
out.Rx = stat.TotalRx()
1139-
out.Tx = stat.TotalTx()
1140-
out.LastOK = stat.LatestRecentHandshake()
11411128
out.Addr = w.IfAddr() // may be empty
1129+
out.Rx = -1
1130+
out.Tx = -2
1131+
out.LastOK = -3
11421132
out.ErrRx = w.errRx.Load()
11431133
out.ErrTx = w.errTx.Load()
11441134
out.LastRx = w.latestRx.Load()
@@ -1149,7 +1139,21 @@ func (w *wgproxy) Stat() (out *x.RouterStats) {
11491139
out.Since = w.since
11501140
out.Status = pxstatus(w.status.Load()).String()
11511141

1142+
if w.status.Load() == END {
1143+
log.W("proxy: wg: %s stats: stopped", w.tag())
1144+
return // zz
1145+
}
1146+
1147+
stat := wg.ReadStats(w.id, w.Handle(), w.Device.IpcGet)
1148+
if stat != nil { // unlikely
1149+
out.Rx = stat.TotalRx()
1150+
out.Tx = stat.TotalTx()
1151+
out.LastOK = stat.LatestRecentHandshake()
1152+
}
1153+
11521154
if settings.Debug {
1155+
out.Extra = w.remote.Load().String() + "\n" + w.dns.Load().String()
1156+
11531157
log.VV("proxy: wg: %s stats: rx: %d, tx: %d, r: %s (rlastok: %s), w: %s (wlastok: %s), lastok: %s",
11541158
w.tag(), out.Rx, out.Tx,
11551159
core.FmtUnixMillisAsPeriod(out.LastRx), core.FmtUnixMillisAsPeriod(out.LastGoodRx),

0 commit comments

Comments
 (0)