package utils import ( "fmt" "html/template" "runtime" "strings" "time" "Moonshark/core/metadata" "Moonshark/core/utils/config" ) // 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 } // SystemStats represents system statistics for debugging type SystemStats struct { Timestamp time.Time GoVersion string GoRoutines int Memory runtime.MemStats Components ComponentStats Version string Config *config.Config } // CollectSystemStats gathers basic system statistics 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 return stats } // DebugStatsPage generates an HTML debug stats page func DebugStatsPage(stats SystemStats) string { const debugTemplate = `
Version | {{.Version}} |
---|
Go Version | {{.GoVersion}} |
---|---|
Goroutines | {{.GoRoutines}} |
Allocated | {{ByteCount .Memory.Alloc}} |
---|---|
Total Allocated | {{ByteCount .Memory.TotalAlloc}} |
System Memory | {{ByteCount .Memory.Sys}} |
GC Cycles | {{.Memory.NumGC}} |
Interpreter | LuaJIT 2.1 (Lua 5.1) |
---|---|
Active Routes | {{.Components.RouteCount}} |
Bytecode Size | {{ByteCount .Components.BytecodeBytes}} |
Loaded Modules | {{.Components.ModuleCount}} |
State Pool Size | {{.Config.Runner.PoolSize}} |
Port | {{.Config.Server.Port}} |
---|---|
Pool Size | {{.Config.Runner.PoolSize}} |
Debug Mode | {{.Config.Server.Debug}} |
Log Level | {{.Config.Server.LogLevel}} |
HTTP Logging | {{.Config.Server.HTTPLogging}} |
Directories |
Routes: {{.Config.Dirs.Routes}}
Static: {{.Config.Dirs.Static}}
Override: {{.Config.Dirs.Override}}
Libs: {{range .Config.Dirs.Libs}}{{.}}, {{end}}
|