High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: add Go runtime metrics and rateBucketHosts to /metrics
Boschdcd331ba74eb
diff --git a/internal/handlers/metrics.go b/internal/handlers/metrics.goindex 046b312f..848d5202 100644--- a/internal/handlers/metrics.go+++ b/internal/handlers/metrics.go@@ -1,11 +1,21 @@package handlers-import "sync/atomic"+import (+ "runtime"+ "sync/atomic"+)func recordStaleRefRetry() {atomic.AddUint64(&metricStaleRefRetries, 1)}+// RateBucketHostCount returns the number of unique hosts in rate limit tracking+func RateBucketHostCount() int {+ rateMu.Lock()+ defer rateMu.Unlock()+ return len(rateBuckets)+}+func snapshotMetrics() map[string]any {total := atomic.LoadUint64(&metricRequestsTotal)failed := atomic.LoadUint64(&metricRequestsFailed)@@ -14,11 +24,23 @@ func snapshotMetrics() map[string]any {if total > 0 {avgMs = float64(latencySum) / float64(total)}++ // Go runtime metrics+ var memStats runtime.MemStats+ runtime.ReadMemStats(&memStats)+return map[string]any{- "requestsTotal": total,- "requestsFailed": failed,- "avgLatencyMs": avgMs,- "rateLimited": atomic.LoadUint64(&metricRateLimited),- "staleRefRetries": atomic.LoadUint64(&metricStaleRefRetries),+ "requestsTotal": total,+ "requestsFailed": failed,+ "avgLatencyMs": avgMs,+ "rateLimited": atomic.LoadUint64(&metricRateLimited),+ "staleRefRetries": atomic.LoadUint64(&metricStaleRefRetries),+ "rateBucketHosts": RateBucketHostCount(),+ "goHeapAllocMB": float64(memStats.HeapAlloc) / (1024 * 1024),+ "goHeapSysMB": float64(memStats.HeapSys) / (1024 * 1024),+ "goNumGoroutine": runtime.NumGoroutine(),+ "goHeapObjects": memStats.HeapObjects,+ "goGCPauseNs": memStats.PauseNs[(memStats.NumGC+255)%256], // Last GC pause+ "goNumGC": memStats.NumGC,}}