MCPcopy Create free account
hub / github.com/Hidden-Node/GooseRelayVPN-AndroidClient / accountStatsLine

Method accountStatsLine

internal/carrier/stats.go:119–171  ·  view source on GitHub ↗

accountStatsLine returns " accounts=[...]" suffix when at least one endpoint carries an account label, or "" otherwise. Aggregates the daily client-side count and (when available) the script-reported count per account so the operator can directly read each Google account's spend against its ~20k/day

()

Source from the content-addressed store, hash-verified

117// at the same count, which would undercount by one — negligible at the
118// thousand-call scale these counters operate at.
119func (c *Client) accountStatsLine() string {
120 c.endpointMu.Lock()
121 defer c.endpointMu.Unlock()
122
123 type agg struct {
124 today uint64
125 scriptCounts map[uint64]struct{} // distinct script-reported counts seen for this account
126 }
127 totals := map[string]*agg{}
128 now := time.Now()
129 hasAny := false
130 for i := range c.endpoints {
131 ep := &c.endpoints[i]
132 if ep.account == "" {
133 continue
134 }
135 hasAny = true
136 c.touchDailyWindow(ep, now)
137 a, ok := totals[ep.account]
138 if !ok {
139 a = &agg{scriptCounts: map[uint64]struct{}{}}
140 totals[ep.account] = a
141 }
142 a.today += ep.dailyCount
143 if !ep.scriptCountAt.IsZero() {
144 a.scriptCounts[ep.scriptCount] = struct{}{}
145 }
146 }
147 if !hasAny {
148 return ""
149 }
150
151 names := make([]string, 0, len(totals))
152 for name := range totals {
153 names = append(names, name)
154 }
155 sort.Strings(names)
156
157 parts := make([]string, 0, len(names))
158 for _, name := range names {
159 a := totals[name]
160 s := fmt.Sprintf("%s today=%d", name, a.today)
161 if len(a.scriptCounts) > 0 {
162 var script uint64
163 for v := range a.scriptCounts {
164 script += v
165 }
166 s = fmt.Sprintf("%s script=%d", s, script)
167 }
168 parts = append(parts, s)
169 }
170 return " accounts=[" + strings.Join(parts, " | ") + "]"
171}
172
173// humanBytes formats a byte count as a short human-readable string. Used for
174// stats lines that an operator scans visually.

Calls 1

touchDailyWindowMethod · 0.95