mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-08 14:01:31 +02:00
Saves 86 KB. And stop depending on expvar and usermetrics when disabled, in prep to removing all the expvar/metrics/tsweb stuff. Updates #12614 Change-Id: I35d2479ddd1d39b615bab32b1fa940ae8cbf9b11 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !ts_omit_health && !ts_omit_usermetrics
|
|
|
|
package health
|
|
|
|
import (
|
|
"expvar"
|
|
|
|
"tailscale.com/feature/buildfeatures"
|
|
"tailscale.com/util/usermetric"
|
|
)
|
|
|
|
const MetricLabelWarning = "warning"
|
|
|
|
type metricHealthMessageLabel struct {
|
|
// TODO: break down by warnable.severity as well?
|
|
Type string
|
|
}
|
|
|
|
// SetMetricsRegistry sets up the metrics for the Tracker. It takes
|
|
// a usermetric.Registry and registers the metrics there.
|
|
func (t *Tracker) SetMetricsRegistry(reg *usermetric.Registry) {
|
|
if !buildfeatures.HasHealth {
|
|
return
|
|
}
|
|
|
|
if reg == nil || t.metricHealthMessage != nil {
|
|
return
|
|
}
|
|
|
|
m := usermetric.NewMultiLabelMapWithRegistry[metricHealthMessageLabel](
|
|
reg,
|
|
"tailscaled_health_messages",
|
|
"gauge",
|
|
"Number of health messages broken down by type.",
|
|
)
|
|
|
|
m.Set(metricHealthMessageLabel{
|
|
Type: MetricLabelWarning,
|
|
}, expvar.Func(func() any {
|
|
if t.nil() {
|
|
return 0
|
|
}
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
t.updateBuiltinWarnablesLocked()
|
|
return int64(len(t.stringsLocked()))
|
|
}))
|
|
t.metricHealthMessage = m
|
|
}
|