diff --git a/core/http/server.go b/core/http/server.go index f90002a..d2b214a 100644 --- a/core/http/server.go +++ b/core/http/server.go @@ -218,14 +218,11 @@ func (s *Server) handleDebugStats(ctx *fasthttp.RequestCtx) { stats := utils.CollectSystemStats(s.config) routeCount, bytecodeBytes := s.luaRouter.GetRouteStats() - //stateCount := s.luaRunner.GetStateCount() - //activeStates := s.luaRunner.GetActiveStateCount() stats.Components = utils.ComponentStats{ RouteCount: routeCount, BytecodeBytes: bytecodeBytes, - //StatesCount: stateCount, - //ActiveStates: activeStates, + SessionStats: sessions.GlobalSessionManager.GetCacheStats(), } ctx.SetContentType("text/html; charset=utf-8") diff --git a/core/sessions/manager.go b/core/sessions/manager.go index 2ca96c0..a84018e 100644 --- a/core/sessions/manager.go +++ b/core/sessions/manager.go @@ -246,3 +246,22 @@ func (sm *SessionManager) CookieOptions() map[string]any { // GlobalSessionManager is the default session manager instance var GlobalSessionManager = NewSessionManager(DefaultMaxSessions) + +// GetCacheStats returns statistics about the session cache +func (sm *SessionManager) GetCacheStats() map[string]uint64 { + if sm == nil || sm.cache == nil { + return map[string]uint64{} + } + + var stats fastcache.Stats + sm.cache.UpdateStats(&stats) + + return map[string]uint64{ + "entries": stats.EntriesCount, + "bytes": stats.BytesSize, + "max_bytes": stats.MaxBytesSize, + "gets": stats.GetCalls, + "sets": stats.SetCalls, + "misses": stats.Misses, + } +} diff --git a/core/utils/debug.go b/core/utils/debug.go index e973807..10bc085 100644 --- a/core/utils/debug.go +++ b/core/utils/debug.go @@ -13,9 +13,10 @@ import ( // ComponentStats holds stats from various system components type ComponentStats struct { - RouteCount int // Number of routes - BytecodeBytes int64 // Total size of bytecode in bytes - ModuleCount int // Number of loaded modules + RouteCount int // Number of routes + BytecodeBytes int64 // Total size of bytecode in bytes + ModuleCount int // Number of loaded modules + SessionStats map[string]uint64 // Session cache statistics } // SystemStats represents system statistics for debugging @@ -34,14 +35,12 @@ func CollectSystemStats(cfg *config.Config) SystemStats { var stats SystemStats var mem runtime.MemStats - // Collect basic system info stats.Timestamp = time.Now() stats.GoVersion = runtime.Version() stats.GoRoutines = runtime.NumGoroutine() stats.Version = metadata.Version stats.Config = cfg - // Collect memory stats runtime.ReadMemStats(&mem) stats.Memory = mem @@ -121,6 +120,20 @@ table tr:nth-child(even), tbody tr:nth-child(even) { background-color: rgba(0, 0 +
+

Sessions

+
+ + + + + + + +
Active Sessions{{index .Components.SessionStats "entries"}}
Cache Size{{ByteCount (index .Components.SessionStats "bytes")}}
Max Cache Size{{ByteCount (index .Components.SessionStats "max_bytes")}}
Cache Gets{{index .Components.SessionStats "gets"}}
Cache Sets{{index .Components.SessionStats "sets"}}
Cache Misses{{index .Components.SessionStats "misses"}}
+
+
+

LuaRunner

@@ -161,10 +174,9 @@ table tr:nth-child(even), tbody tr:nth-child(even) { background-color: rgba(0, 0 // Create a template function map funcMap := template.FuncMap{ - "ByteCount": func(b interface{}) string { + "ByteCount": func(b any) string { var bytes uint64 - // Convert the value to uint64 switch v := b.(type) { case uint64: bytes = v @@ -173,7 +185,7 @@ table tr:nth-child(even), tbody tr:nth-child(even) { background-color: rgba(0, 0 case int: bytes = uint64(v) default: - return "Unknown" + return fmt.Sprintf("%T: %v", b, b) } const unit = 1024