Add real-time log monitoring and system stats dashboard
Implements a comprehensive monitoring system for the admin interface: Backend: - New monitoring package with Redis ring buffer for log storage - Zerolog MultiWriter to capture logs to Redis - System stats collection (CPU, memory, disk, goroutines, GC) - HTTP metrics middleware (request counts, latency, error rates) - Asynq queue stats for worker process - WebSocket endpoint for real-time log streaming - Admin auth middleware now accepts token in query params (for WebSocket) Frontend: - New monitoring page with tabs (Overview, Logs, API Stats, Worker Stats) - Real-time log viewer with level filtering and search - System stats cards showing CPU, memory, goroutines, uptime - HTTP endpoint statistics table - Asynq queue depth visualization - Enable/disable monitoring toggle in settings Memory safeguards: - Max 200 unique endpoints tracked - Hourly stats reset to prevent unbounded growth - Max 1000 log entries in ring buffer - Max 1000 latency samples for P95 calculation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -12,22 +12,48 @@ import (
|
||||
|
||||
// InitLogger initializes the zerolog logger
|
||||
func InitLogger(debug bool) {
|
||||
InitLoggerWithWriter(debug, nil)
|
||||
}
|
||||
|
||||
// InitLoggerWithWriter initializes the zerolog logger with an optional additional writer
|
||||
// The additional writer receives JSON formatted logs (useful for monitoring)
|
||||
func InitLoggerWithWriter(debug bool, additionalWriter io.Writer) {
|
||||
zerolog.TimeFieldFormat = time.RFC3339
|
||||
|
||||
var output io.Writer = os.Stdout
|
||||
|
||||
if debug {
|
||||
// Pretty console output for development
|
||||
output = zerolog.ConsoleWriter{
|
||||
Out: os.Stdout,
|
||||
TimeFormat: "15:04:05",
|
||||
}
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
} else {
|
||||
// JSON output for production
|
||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||
}
|
||||
|
||||
// Build the output writer(s)
|
||||
var output io.Writer
|
||||
|
||||
if additionalWriter != nil {
|
||||
// Always write JSON to additional writer for monitoring
|
||||
// The additional writer parses JSON to extract log entries
|
||||
if debug {
|
||||
// In debug mode: pretty console to stdout + JSON to additional writer
|
||||
consoleOutput := zerolog.ConsoleWriter{
|
||||
Out: os.Stdout,
|
||||
TimeFormat: "15:04:05",
|
||||
}
|
||||
output = io.MultiWriter(consoleOutput, additionalWriter)
|
||||
} else {
|
||||
// In production: JSON to both stdout and additional writer
|
||||
output = io.MultiWriter(os.Stdout, additionalWriter)
|
||||
}
|
||||
} else {
|
||||
if debug {
|
||||
output = zerolog.ConsoleWriter{
|
||||
Out: os.Stdout,
|
||||
TimeFormat: "15:04:05",
|
||||
}
|
||||
} else {
|
||||
output = os.Stdout
|
||||
}
|
||||
}
|
||||
|
||||
log.Logger = zerolog.New(output).With().Timestamp().Caller().Logger()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user