MCPcopy Create free account
hub / github.com/PasarGuard/node / recordSystemStats

Method recordSystemStats

controller/controller.go:170–198  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

168}
169
170func (c *Controller) recordSystemStats(ctx context.Context) {
171 interval := 1500 * time.Millisecond
172
173 ticker := time.NewTicker(interval)
174 defer ticker.Stop()
175
176 collect := func() {
177 stats, err := sysstats.GetSystemStats()
178 if err != nil {
179 log.Printf("Failed to get system stats: %v", err)
180 return
181 }
182
183 c.mu.Lock()
184 c.stats = stats
185 c.mu.Unlock()
186 }
187
188 collect()
189
190 for {
191 select {
192 case <-ctx.Done():
193 return
194 case <-ticker.C:
195 collect()
196 }
197 }
198}
199
200func (c *Controller) SystemStats(ctx context.Context) *common.SystemStatsResponse {
201 c.mu.RLock()

Callers 1

ConnectMethod · 0.95

Calls 2

GetSystemStatsFunction · 0.92
StopMethod · 0.65

Tested by

no test coverage detected