ipn/ipnlocal, health: add home DERP region usermetric

Fixes #18061

Signed-off-by: Raj Singh <raj@tailscale.com>
pull/18062/head
Raj Singh 1 week ago
parent b38dd1ae06
commit b75c3eeaa8

@ -761,6 +761,16 @@ func (t *Tracker) SetMagicSockDERPHome(region int, homeless bool) {
t.selfCheckLocked() t.selfCheckLocked()
} }
// DERPHomeRegion returns the current home DERP region ID, or 0 if unknown.
func (t *Tracker) DERPHomeRegion() int {
if t.nil() {
return 0
}
t.mu.Lock()
defer t.mu.Unlock()
return t.derpHomeRegion
}
// NoteMapRequestHeard notes whenever we successfully sent a map request // NoteMapRequestHeard notes whenever we successfully sent a map request
// to control for which we received a 200 response. // to control for which we received a 200 response.
func (t *Tracker) NoteMapRequestHeard(mr *tailcfg.MapRequest) { func (t *Tracker) NoteMapRequestHeard(mr *tailcfg.MapRequest) {

@ -439,6 +439,8 @@ type metrics struct {
// approvedRoutes is a metric that reports the number of network routes served by the local node and approved // approvedRoutes is a metric that reports the number of network routes served by the local node and approved
// by the control server. // by the control server.
approvedRoutes *usermetric.Gauge approvedRoutes *usermetric.Gauge
homeDERP *usermetric.Gauge
} }
// clientGen is a func that creates a control plane client. // clientGen is a func that creates a control plane client.
@ -490,6 +492,8 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo
"tailscaled_advertised_routes", "Number of advertised network routes (e.g. by a subnet router)"), "tailscaled_advertised_routes", "Number of advertised network routes (e.g. by a subnet router)"),
approvedRoutes: sys.UserMetricsRegistry().NewGauge( approvedRoutes: sys.UserMetricsRegistry().NewGauge(
"tailscaled_approved_routes", "Number of approved network routes (e.g. by a subnet router)"), "tailscaled_approved_routes", "Number of approved network routes (e.g. by a subnet router)"),
homeDERP: sys.UserMetricsRegistry().NewGauge(
"tailscaled_home_derp_region_id", "DERP region ID of this node's home relay server"),
} }
b := &LocalBackend{ b := &LocalBackend{
@ -6153,6 +6157,8 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
} }
} }
b.metrics.homeDERP.Set(float64(b.health.DERPHomeRegion()))
if buildfeatures.HasDrive && nm != nil { if buildfeatures.HasDrive && nm != nil {
if f, ok := hookSetNetMapLockedDrive.GetOk(); ok { if f, ok := hookSetNetMapLockedDrive.GetOk(); ok {
f(b, nm) f(b, nm)

Loading…
Cancel
Save