mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 13:18:53 +00:00
net/netmon, net/tsdial: add some link change metrics
Updates #9040 Change-Id: I2c87572d79d2118bcf1f0122eccfe712c1bea9d5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
8683ce78c2
commit
1262df0578
@@ -23,6 +23,7 @@ import (
|
||||
"tailscale.com/net/netns"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/netmap"
|
||||
"tailscale.com/util/clientmetric"
|
||||
"tailscale.com/util/mak"
|
||||
)
|
||||
|
||||
@@ -138,16 +139,25 @@ func (d *Dialer) SetNetMon(netMon *netmon.Monitor) {
|
||||
d.netMonUnregister = d.netMon.RegisterChangeCallback(d.linkChanged)
|
||||
}
|
||||
|
||||
var (
|
||||
metricLinkChangeConnClosed = clientmetric.NewCounter("tsdial_linkchange_closes")
|
||||
)
|
||||
|
||||
func (d *Dialer) linkChanged(delta *netmon.ChangeDelta) {
|
||||
d.mu.Lock()
|
||||
defer d.mu.Unlock()
|
||||
var anyClosed bool
|
||||
for id, c := range d.activeSysConns {
|
||||
if changeAffectsConn(delta, c) {
|
||||
anyClosed = true
|
||||
d.logf("tsdial: closing system connection %v->%v due to link change", c.LocalAddr(), c.RemoteAddr())
|
||||
go c.Close()
|
||||
delete(d.activeSysConns, id)
|
||||
}
|
||||
}
|
||||
if anyClosed {
|
||||
metricLinkChangeConnClosed.Add(1)
|
||||
}
|
||||
}
|
||||
|
||||
// changeAffectsConn reports whether the network change delta affects
|
||||
|
Reference in New Issue
Block a user