|
|
@ -9,19 +9,18 @@ import (
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
"tailscale.com/net/tcpinfo"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (c *sclient) statsLoop(ctx context.Context) error {
|
|
|
|
func (c *sclient) statsLoop(ctx context.Context) error {
|
|
|
|
// If we can't get a TCP socket, then we can't send stats.
|
|
|
|
// Get the RTT initially to verify it's supported.
|
|
|
|
tcpConn := c.tcpConn()
|
|
|
|
conn := c.tcpConn()
|
|
|
|
if tcpConn == nil {
|
|
|
|
if conn == nil {
|
|
|
|
c.s.tcpRtt.Add("non-tcp", 1)
|
|
|
|
c.s.tcpRtt.Add("non-tcp", 1)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rawConn, err := tcpConn.SyscallConn()
|
|
|
|
if _, err := tcpinfo.RTT(conn); err != nil {
|
|
|
|
if err != nil {
|
|
|
|
c.logf("error fetching initial RTT: %v", err)
|
|
|
|
c.logf("error getting SyscallConn: %v", err)
|
|
|
|
|
|
|
|
c.s.tcpRtt.Add("error", 1)
|
|
|
|
c.s.tcpRtt.Add("error", 1)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -31,23 +30,16 @@ func (c *sclient) statsLoop(ctx context.Context) error {
|
|
|
|
ticker := time.NewTicker(statsInterval)
|
|
|
|
ticker := time.NewTicker(statsInterval)
|
|
|
|
defer ticker.Stop()
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
tcpInfo *unix.TCPInfo
|
|
|
|
|
|
|
|
sysErr error
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
statsLoop:
|
|
|
|
statsLoop:
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
|
|
|
case <-ticker.C:
|
|
|
|
err = rawConn.Control(func(fd uintptr) {
|
|
|
|
rtt, err := tcpinfo.RTT(conn)
|
|
|
|
tcpInfo, sysErr = unix.GetsockoptTCPInfo(int(fd), unix.IPPROTO_TCP, unix.TCP_INFO)
|
|
|
|
if err != nil {
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil || sysErr != nil {
|
|
|
|
|
|
|
|
continue statsLoop
|
|
|
|
continue statsLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(andrew): more metrics?
|
|
|
|
// TODO(andrew): more metrics?
|
|
|
|
rtt := time.Duration(tcpInfo.Rtt) * time.Microsecond
|
|
|
|
|
|
|
|
c.s.tcpRtt.Add(durationToLabel(rtt), 1)
|
|
|
|
c.s.tcpRtt.Add(durationToLabel(rtt), 1)
|
|
|
|
|
|
|
|
|
|
|
|
case <-ctx.Done():
|
|
|
|
case <-ctx.Done():
|
|
|
|