diff --git a/net/tstun/tun.go b/net/tstun/tun.go index 0945df476..3e2fbbae5 100644 --- a/net/tstun/tun.go +++ b/net/tstun/tun.go @@ -87,6 +87,7 @@ func New(logf logger.Logf, tunName string) (tun.Device, string, error) { if err != nil { return nil, "", err } + metricQueues.Set(int64(len(tun.QueuesOf(dev)))) if err := waitInterfaceUp(dev, 90*time.Second, logf); err != nil { dev.Close() return nil, "", err diff --git a/net/tstun/wrap.go b/net/tstun/wrap.go index 4449f0868..29dd805d5 100644 --- a/net/tstun/wrap.go +++ b/net/tstun/wrap.go @@ -1605,6 +1605,8 @@ func (t *Wrapper) SetConnectionCounter(fn netlogfunc.ConnectionCounter) { } var ( + metricQueues = clientmetric.NewGauge("tstun_queues") + metricPacketIn = clientmetric.NewCounter("tstun_in_from_wg") metricPacketInDrop = clientmetric.NewCounter("tstun_in_from_wg_drop") metricPacketInDropFilter = clientmetric.NewCounter("tstun_in_from_wg_drop_filter") diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 0a92bbde3..edda0be72 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -3963,6 +3963,13 @@ func (c *Conn) bindSocket(ruc *RebindingUDPConn, network string, curPortFate cur // from the perspective of ruc receive functions. ruc.mu.Lock() defer ruc.mu.Unlock() + defer func() { + m := metricUDPSocketsIPv4 + if network == "udp6" { + m = metricUDPSocketsIPv6 + } + m.Set(int64(ruc.group.bound)) + }() if c.closing.Load() { return net.ErrClosed @@ -4449,6 +4456,9 @@ var ( metricNumPeers = clientmetric.NewGauge("magicsock_netmap_num_peers") metricNumDERPConns = clientmetric.NewGauge("magicsock_num_derp_conns") + metricUDPSocketsIPv4 = clientmetric.NewGauge("magicsock_udp_sockets_ipv4") + metricUDPSocketsIPv6 = clientmetric.NewGauge("magicsock_udp_sockets_ipv6") + metricRebindCalls = clientmetric.NewCounter("magicsock_rebind_calls") metricReSTUNCalls = clientmetric.NewCounter("magicsock_restun_calls") metricUpdateEndpoints = clientmetric.NewCounter("magicsock_update_endpoints") diff --git a/wgengine/magicsock/reuseport_test.go b/wgengine/magicsock/reuseport_test.go index e8a685c6d..e0b9e90a0 100644 --- a/wgengine/magicsock/reuseport_test.go +++ b/wgengine/magicsock/reuseport_test.go @@ -25,6 +25,9 @@ func TestUDPSockets(t *testing.T) { if got := ruc.group.bound; got != sockets { t.Fatalf("bound %d sockets, want %d", got, sockets) } + if got := metricUDPSocketsIPv4.Value(); got != int64(sockets) { + t.Errorf("metric reports %d sockets, want %d", got, sockets) + } for i, pconn := range ruc.group.conns[:ruc.group.bound] { if got := uint16(pconn.LocalAddr().(*net.UDPAddr).Port); got != ruc.Port() { t.Errorf("socket %d bound to port %d, want %d", i, got, ruc.Port())