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

Method GetStats

backend/wireguard/stats.go:60–86  ·  view source on GitHub ↗
(ctx context.Context, request *common.StatRequest)

Source from the content-addressed store, hash-verified

58}
59
60func (wg *WireGuard) GetStats(ctx context.Context, request *common.StatRequest) (*common.StatResponse, error) {
61 wg.mu.RLock()
62 state := wg.state
63 wg.mu.RUnlock()
64
65 if state != lifecycleRunning {
66 return nil, errWireGuardNotStarted
67 }
68
69 switch request.GetType() {
70 case common.StatType_UserStat:
71 return wg.handleUserStats(ctx, request)
72
73 case common.StatType_UsersStat:
74 return wg.handleUsersStats(ctx, request)
75
76 case common.StatType_Outbound, common.StatType_Outbounds:
77 // handleInterfaceOutboundStats falls back to the configured interface name when GetName() is empty,
78 // so both stat types are satisfied by the same call.
79 return wg.handleInterfaceOutboundStats(request.GetName(), request.GetReset_())
80
81 case common.StatType_Inbound, common.StatType_Inbounds:
82 return nil, errors.New("inbound stats not applicable for wireguard")
83 default:
84 return nil, errors.New("unsupported stat type")
85 }
86}
87
88func (wg *WireGuard) GetUserOnlineStats(ctx context.Context, email string) (*common.OnlineStatResponse, error) {
89 wg.mu.RLock()

Calls 6

handleUserStatsMethod · 0.95
handleUsersStatsMethod · 0.95
GetReset_Method · 0.80
GetTypeMethod · 0.45
GetNameMethod · 0.45