Add connection duration and reconnect count to status page

- Track reconnection count in metrics tracker
- Display connection duration under Stream Statistics
- Display reconnect count since app startup
- Update both JSON API and HTML status page
This commit is contained in:
2025-12-30 14:33:37 +07:00
parent 3a9ec98d5c
commit 9043cf9bc0
3 changed files with 36 additions and 1 deletions

View File

@@ -330,6 +330,8 @@ func (s *Server) handleStats() http.HandlerFunc {
MbitsPerSec float64 `json:"mbits_per_sec"`
WireMbitsPerSec float64 `json:"wire_mbits_per_sec"`
Connected bool `json:"connected"`
ConnectionDuration string `json:"connection_duration"`
ReconnectCount uint64 `json:"reconnect_count"`
GoVersion string `json:"go_version"`
Goroutines int `json:"goroutines"`
MemoryUsage string `json:"memory_usage"`
@@ -442,6 +444,12 @@ func (s *Server) handleStats() http.HandlerFunc {
whoisStats = s.getWHOISStats(ctx)
}
// Calculate connection duration
connectionDuration := "disconnected"
if metrics.Connected && !metrics.ConnectedSince.IsZero() {
connectionDuration = time.Since(metrics.ConnectedSince).Truncate(time.Second).String()
}
stats := StatsResponse{
Uptime: uptime,
TotalMessages: metrics.TotalMessages,
@@ -451,6 +459,8 @@ func (s *Server) handleStats() http.HandlerFunc {
MbitsPerSec: metrics.BitsPerSec / bitsPerMegabit,
WireMbitsPerSec: metrics.WireBitsPerSec / bitsPerMegabit,
Connected: metrics.Connected,
ConnectionDuration: connectionDuration,
ReconnectCount: metrics.ReconnectCount,
GoVersion: runtime.Version(),
Goroutines: runtime.NumGoroutine(),
MemoryUsage: humanize.Bytes(memStats.Alloc),