mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-25 03:01:18 -08: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 <[email protected]>
This commit is contained in:
1 parent
9613b4eecc
commit
887bfc3bc5
3 files changed
+42
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {}
|
||||
Reference in new issue
Block a user