mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-24 02:31:48 +01:00
logpolicy: expose certain metrics as clientmetrics
This allows us to detect how often we are actually filching (and therefore whether to maintain this feature). It also reports the storage size and amount of dropped bytes. Updates tailscale/corp#21363 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
9613b4eecc
commit
887bfc3bc5
@ -662,6 +662,9 @@ func (opts Options) init(disableLogging bool) (*logtail.Config, *Policy) {
|
||||
}
|
||||
}
|
||||
lw := logtail.NewLogger(conf, opts.Logf)
|
||||
if conf.MetricsDelta != nil {
|
||||
exportClientMetrics(lw)
|
||||
}
|
||||
|
||||
var logOutput io.Writer = lw
|
||||
|
||||
|
||||
29
logpolicy/logtail_metrics.go
Normal file
29
logpolicy/logtail_metrics.go
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build !ts_omit_logtail && !ts_omit_clientmetrics
|
||||
|
||||
package logpolicy
|
||||
|
||||
import (
|
||||
"expvar"
|
||||
|
||||
"tailscale.com/logtail"
|
||||
"tailscale.com/util/clientmetric"
|
||||
)
|
||||
|
||||
func exportClientMetrics(logger *logtail.Logger) {
|
||||
if m, _ := logger.ExpVar().(interface{ Get(string) expvar.Var }); m != nil {
|
||||
if m2, _ := m.Get("buffer").(interface{ Get(string) expvar.Var }); m2 != nil {
|
||||
if v, _ := m2.Get("counter_filched_bytes").(*expvar.Int); v != nil {
|
||||
clientmetric.NewCounterFunc("logtail_filched_bytes", v.Value)
|
||||
}
|
||||
if v, _ := m2.Get("counter_dropped_bytes").(*expvar.Int); v != nil {
|
||||
clientmetric.NewCounterFunc("logtail_dropped_bytes", v.Value)
|
||||
}
|
||||
if v, _ := m2.Get("gauge_stored_bytes").(*expvar.Int); v != nil {
|
||||
clientmetric.NewGaugeFunc("logtail_stored_bytes", v.Value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
logpolicy/logtail_nometrics.go
Normal file
10
logpolicy/logtail_nometrics.go
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build ts_omit_logtail || ts_omit_clientmetrics
|
||||
|
||||
package logpolicy
|
||||
|
||||
import "tailscale.com/logtail"
|
||||
|
||||
func exportClientMetrics(logger *logtail.Logger) {}
|
||||
Loading…
x
Reference in New Issue
Block a user