MCPcopy
hub / github.com/tailscale/tailscale / runMonitor

Function runMonitor

cmd/tailscaled/debug.go:101–129  ·  view source on GitHub ↗
(ctx context.Context, loop bool)

Source from the content-addressed store, hash-verified

99}
100
101func runMonitor(ctx context.Context, loop bool) error {
102 b := eventbus.New()
103 defer b.Close()
104
105 dump := func(st *netmon.State) {
106 j, _ := json.MarshalIndent(st, "", " ")
107 os.Stderr.Write(j)
108 }
109 mon, err := netmon.New(b, log.Printf)
110 if err != nil {
111 return err
112 }
113 defer mon.Close()
114
115 eventClient := b.Client("debug.runMonitor")
116 m := eventClient.Monitor(changeDeltaWatcher(eventClient, ctx, dump))
117 defer m.Close()
118
119 if loop {
120 log.Printf("Starting link change monitor; initial state:")
121 }
122 dump(mon.InterfaceState())
123 if !loop {
124 return nil
125 }
126 mon.Start()
127 log.Printf("Started link change monitor; waiting...")
128 select {}
129}
130
131func changeDeltaWatcher(ec *eventbus.Client, ctx context.Context, dump func(st *netmon.State)) func(*eventbus.Client) {
132 changeSub := eventbus.Subscribe[netmon.ChangeDelta](ec)

Callers 1

debugModeFunction · 0.85

Calls 10

NewFunction · 0.92
NewFunction · 0.92
changeDeltaWatcherFunction · 0.85
MonitorMethod · 0.80
PrintfMethod · 0.80
InterfaceStateMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.65
ClientMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…