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

Method GetSysStats

backend/wireguard/stats.go:154–187  ·  view source on GitHub ↗

GetSysStats returns system stats for the WireGuard backend

(ctx context.Context)

Source from the content-addressed store, hash-verified

152
153// GetSysStats returns system stats for the WireGuard backend
154func (wg *WireGuard) GetSysStats(ctx context.Context) (*common.BackendStatsResponse, error) {
155 wg.mu.RLock()
156 state := wg.state
157 mgr := wg.manager
158 wg.mu.RUnlock()
159
160 if err := lifecycleReadinessError(state); err != nil {
161 return nil, err
162 }
163 if mgr == nil {
164 return nil, errWireGuardManagerNotInitialized
165 }
166 if _, _, err := mgr.GetInterfaceStats(); err != nil {
167 return nil, fmt.Errorf("wireguard interface not available: %w", err)
168 }
169
170 var memStats runtime.MemStats
171 runtime.ReadMemStats(&memStats)
172
173 stats := common.BackendStatsResponse{
174 NumGoroutine: uint32(runtime.NumGoroutine()),
175 NumGc: memStats.NumGC,
176 Alloc: memStats.Alloc,
177 TotalAlloc: memStats.TotalAlloc,
178 Sys: memStats.Sys,
179 Mallocs: memStats.Mallocs,
180 Frees: memStats.Frees,
181 LiveObjects: memStats.Mallocs - memStats.Frees,
182 PauseTotalNs: memStats.PauseTotalNs,
183 Uptime: uint32(time.Since(wg.startTime).Seconds()),
184 }
185
186 return &stats, nil
187}

Calls 2

lifecycleReadinessErrorFunction · 0.85
GetInterfaceStatsMethod · 0.80