mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-07 08:07:42 +00:00
net/sockstats: export cellular-only clientmetrics
Followup to #7518 to also export client metrics when the active interface is cellular. Updates tailscale/corp#9230 Updates #3363 Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:
parent
e7a78bc28f
commit
d2dec13392
@ -25,7 +25,7 @@ type sockStatCounters struct {
|
|||||||
txBytes, rxBytes atomic.Uint64
|
txBytes, rxBytes atomic.Uint64
|
||||||
rxBytesByInterface, txBytesByInterface map[int]*atomic.Uint64
|
rxBytesByInterface, txBytesByInterface map[int]*atomic.Uint64
|
||||||
|
|
||||||
txBytesMetric, rxBytesMetric *clientmetric.Metric
|
txBytesMetric, rxBytesMetric, txBytesCellularMetric, rxBytesCellularMetric *clientmetric.Metric
|
||||||
|
|
||||||
// Validate counts for TCP sockets by using the TCP_CONNECTION_INFO
|
// Validate counts for TCP sockets by using the TCP_CONNECTION_INFO
|
||||||
// getsockopt. We get current counts, as well as save final values when
|
// getsockopt. We get current counts, as well as save final values when
|
||||||
@ -65,10 +65,12 @@ func withSockStats(ctx context.Context, label Label) context.Context {
|
|||||||
counters, ok := sockStats.countersByLabel[label]
|
counters, ok := sockStats.countersByLabel[label]
|
||||||
if !ok {
|
if !ok {
|
||||||
counters = &sockStatCounters{
|
counters = &sockStatCounters{
|
||||||
rxBytesByInterface: make(map[int]*atomic.Uint64),
|
rxBytesByInterface: make(map[int]*atomic.Uint64),
|
||||||
txBytesByInterface: make(map[int]*atomic.Uint64),
|
txBytesByInterface: make(map[int]*atomic.Uint64),
|
||||||
txBytesMetric: clientmetric.NewCounter(fmt.Sprintf("sockstats_tx_bytes_%s", label)),
|
txBytesMetric: clientmetric.NewCounter(fmt.Sprintf("sockstats_tx_bytes_%s", label)),
|
||||||
rxBytesMetric: clientmetric.NewCounter(fmt.Sprintf("sockstats_rx_bytes_%s", label)),
|
rxBytesMetric: clientmetric.NewCounter(fmt.Sprintf("sockstats_rx_bytes_%s", label)),
|
||||||
|
txBytesCellularMetric: clientmetric.NewCounter(fmt.Sprintf("sockstats_tx_bytes_cellular_%s", label)),
|
||||||
|
rxBytesCellularMetric: clientmetric.NewCounter(fmt.Sprintf("sockstats_rx_bytes_cellular_%s", label)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// We might be called before setLinkMonitor has been called (and we've
|
// We might be called before setLinkMonitor has been called (and we've
|
||||||
@ -119,6 +121,7 @@ func withSockStats(ctx context.Context, label Label) context.Context {
|
|||||||
}
|
}
|
||||||
if sockStats.currentInterfaceCellular.Load() {
|
if sockStats.currentInterfaceCellular.Load() {
|
||||||
sockStats.rxBytesCellularMetric.Add(int64(n))
|
sockStats.rxBytesCellularMetric.Add(int64(n))
|
||||||
|
counters.rxBytesCellularMetric.Add(int64(n))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
didWrite := func(n int) {
|
didWrite := func(n int) {
|
||||||
@ -132,6 +135,7 @@ func withSockStats(ctx context.Context, label Label) context.Context {
|
|||||||
}
|
}
|
||||||
if sockStats.currentInterfaceCellular.Load() {
|
if sockStats.currentInterfaceCellular.Load() {
|
||||||
sockStats.txBytesCellularMetric.Add(int64(n))
|
sockStats.txBytesCellularMetric.Add(int64(n))
|
||||||
|
counters.txBytesCellularMetric.Add(int64(n))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
willOverwrite := func(trace *net.SockTrace) {
|
willOverwrite := func(trace *net.SockTrace) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user