cmd/tailscale/cli: add "debug metrics" subcommand

To let users inspect the tailscaled metrics easily.

Updates #3307

Change-Id: I922126ca0626659948c57de74c6ef62f40ef5f5f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-11-15 15:06:37 -08:00 committed by Brad Fitzpatrick
parent 945290cc3f
commit 68917fdb5d
2 changed files with 24 additions and 4 deletions

View File

@ -196,6 +196,12 @@ func Goroutines(ctx context.Context) ([]byte, error) {
return get200(ctx, "/localapi/v0/goroutines") return get200(ctx, "/localapi/v0/goroutines")
} }
// DaemonMetrics returns the Tailscale daemon's metrics in
// the Prometheus text exposition format.
func DaemonMetrics(ctx context.Context) ([]byte, error) {
return get200(ctx, "/localapi/v0/metrics")
}
// Profile returns a pprof profile of the Tailscale daemon. // Profile returns a pprof profile of the Tailscale daemon.
func Profile(ctx context.Context, pprofType string, sec int) ([]byte, error) { func Profile(ctx context.Context, pprofType string, sec int) ([]byte, error) {
var secArg string var secArg string

View File

@ -46,17 +46,22 @@
Exec: runDaemonGoroutines, Exec: runDaemonGoroutines,
ShortHelp: "print tailscaled's goroutines", ShortHelp: "print tailscaled's goroutines",
}, },
&ffcli.Command{ {
Name: "metrics",
Exec: runDaemonMetrics,
ShortHelp: "print tailscaled's metrics",
},
{
Name: "env", Name: "env",
Exec: runEnv, Exec: runEnv,
ShortHelp: "print cmd/tailscale environment", ShortHelp: "print cmd/tailscale environment",
}, },
&ffcli.Command{ {
Name: "local-creds", Name: "local-creds",
Exec: runLocalCreds, Exec: runLocalCreds,
ShortHelp: "print how to access Tailscale local API", ShortHelp: "print how to access Tailscale local API",
}, },
&ffcli.Command{ {
Name: "prefs", Name: "prefs",
Exec: runPrefs, Exec: runPrefs,
ShortHelp: "print prefs", ShortHelp: "print prefs",
@ -66,7 +71,7 @@
return fs return fs
})(), })(),
}, },
&ffcli.Command{ {
Name: "watch-ipn", Name: "watch-ipn",
Exec: runWatchIPN, Exec: runWatchIPN,
ShortHelp: "subscribe to IPN message bus", ShortHelp: "subscribe to IPN message bus",
@ -245,3 +250,12 @@ func runDaemonGoroutines(ctx context.Context, args []string) error {
Stdout.Write(goroutines) Stdout.Write(goroutines)
return nil return nil
} }
func runDaemonMetrics(ctx context.Context, args []string) error {
out, err := tailscale.DaemonMetrics(ctx)
if err != nil {
return err
}
Stdout.Write(out)
return nil
}