MCPcopy
hub / github.com/tailscale/tailscale / runDaemonMetrics

Function runDaemonMetrics

cmd/tailscale/cli/debug.go:882–933  ·  view source on GitHub ↗
(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

880}
881
882func runDaemonMetrics(ctx context.Context, args []string) error {
883 last := map[string]int64{}
884 for {
885 out, err := localClient.DaemonMetrics(ctx)
886 if err != nil {
887 return err
888 }
889 if !metricsArgs.watch {
890 Stdout.Write(out)
891 return nil
892 }
893 bs := bufio.NewScanner(bytes.NewReader(out))
894 type change struct {
895 name string
896 from, to int64
897 }
898 var changes []change
899 var maxNameLen int
900 for bs.Scan() {
901 line := bytes.TrimSpace(bs.Bytes())
902 if len(line) == 0 || line[0] == '#' {
903 continue
904 }
905 f := strings.Fields(string(line))
906 if len(f) != 2 {
907 continue
908 }
909 name := f[0]
910 n, _ := strconv.ParseInt(f[1], 10, 64)
911 prev, ok := last[name]
912 if ok && prev == n {
913 continue
914 }
915 last[name] = n
916 if !ok {
917 continue
918 }
919 changes = append(changes, change{name, prev, n})
920 if len(name) > maxNameLen {
921 maxNameLen = len(name)
922 }
923 }
924 if len(changes) > 0 {
925 format := fmt.Sprintf("%%-%ds %%+5d => %%v\n", maxNameLen)
926 for _, c := range changes {
927 fmt.Fprintf(Stdout, format, c.name, c.to-c.from, c.to)
928 }
929 io.WriteString(Stdout, "\n")
930 }
931 time.Sleep(time.Second)
932 }
933}
934
935func runVia(ctx context.Context, args []string) error {
936 switch len(args) {

Callers

nothing calls this directly

Calls 5

DaemonMetricsMethod · 0.80
ScanMethod · 0.80
BytesMethod · 0.80
WriteStringMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…