mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
make route a simpler expvar
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
ffe3c43168
commit
c74932009a
@ -12,6 +12,7 @@
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"expvar"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@ -118,6 +119,12 @@
|
||||
"tailscale.com/wgengine/wgcfg/nmcfg"
|
||||
)
|
||||
|
||||
var metricAdvertisedRoutes expvar.Int
|
||||
|
||||
func init() {
|
||||
usermetric.Publish("tailscaled_advertised_routes", &metricAdvertisedRoutes)
|
||||
}
|
||||
|
||||
var controlDebugFlags = getControlDebugFlags()
|
||||
|
||||
func getControlDebugFlags() []string {
|
||||
@ -4615,12 +4622,6 @@ func unmapIPPrefixes(ippsList ...[]netip.Prefix) (ret []netip.Prefix) {
|
||||
return ret
|
||||
}
|
||||
|
||||
var metricAdvertisedRoutes = usermetric.NewMap(
|
||||
"tailscaled_advertised_routes",
|
||||
"gauge",
|
||||
"Number of subnet routes advertised by the node. (excluding exit node /0 routes)",
|
||||
)
|
||||
|
||||
// b.mu must be held.
|
||||
func (b *LocalBackend) applyPrefsToHostinfoLocked(hi *tailcfg.Hostinfo, prefs ipn.PrefsView) {
|
||||
if h := prefs.Hostname(); h != "" {
|
||||
@ -4632,13 +4633,11 @@ func (b *LocalBackend) applyPrefsToHostinfoLocked(hi *tailcfg.Hostinfo, prefs ip
|
||||
hi.AllowsUpdate = envknob.AllowsRemoteUpdate() || prefs.AutoUpdate().Apply.EqualBool(true)
|
||||
|
||||
// count routes without exit node routes
|
||||
routeCount := 0
|
||||
for _, route := range hi.RoutableIPs {
|
||||
if route.Bits() != 0 {
|
||||
routeCount++
|
||||
metricAdvertisedRoutes.Add(1)
|
||||
}
|
||||
}
|
||||
metricAdvertisedRoutes.SetInt(struct{}{}, int64(routeCount))
|
||||
|
||||
var sshHostKeys []string
|
||||
if prefs.RunSSH() && envknob.CanSSHD() {
|
||||
|
@ -33,19 +33,14 @@ func NewMultiLabelMap[T comparable](name string, promType, helpText string) *met
|
||||
return m
|
||||
}
|
||||
|
||||
// NewMap creates and register a new
|
||||
// Map variable with the given name and returns it.
|
||||
// Publish declares a named exported variable. This should be called from a
|
||||
// package's init function when it creates its Vars.
|
||||
//
|
||||
// Note that usermetric are not protected against duplicate
|
||||
// metrics name. It is the caller's responsibility to ensure that
|
||||
// the name is unique.
|
||||
func NewMap(name string, promType, helpText string) *metrics.MultiLabelMap[struct{}] {
|
||||
m := &metrics.MultiLabelMap[struct{}]{
|
||||
Type: promType,
|
||||
Help: helpText,
|
||||
}
|
||||
vars.Set(name, m)
|
||||
return m
|
||||
func Publish(name string, v expvar.Var) {
|
||||
vars.Set(name, v)
|
||||
}
|
||||
|
||||
// Handler returns a varz.Handler that serves the userfacing expvar contained
|
||||
|
Loading…
Reference in New Issue
Block a user