add cache stats to debug page
This commit is contained in:
parent
9ea06eb1b4
commit
27ed139274
@ -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")
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Sessions</h2>
|
||||
<div class="card">
|
||||
<table>
|
||||
<tr><th>Active Sessions</th><td>{{index .Components.SessionStats "entries"}}</td></tr>
|
||||
<tr><th>Cache Size</th><td>{{ByteCount (index .Components.SessionStats "bytes")}}</td></tr>
|
||||
<tr><th>Max Cache Size</th><td>{{ByteCount (index .Components.SessionStats "max_bytes")}}</td></tr>
|
||||
<tr><th>Cache Gets</th><td>{{index .Components.SessionStats "gets"}}</td></tr>
|
||||
<tr><th>Cache Sets</th><td>{{index .Components.SessionStats "sets"}}</td></tr>
|
||||
<tr><th>Cache Misses</th><td>{{index .Components.SessionStats "misses"}}</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>LuaRunner</h2>
|
||||
<div class="card">
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user