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

@@ -15,6 +15,7 @@ type Tracker struct {
registry metrics.Registry
connectedSince time.Time
isConnected atomic.Bool
reconnectCount atomic.Uint64
// Stream metrics (decompressed data)
messageCounter metrics.Counter
@@ -50,14 +51,23 @@ func New() *Tracker {
// SetConnected updates the connection status
func (t *Tracker) SetConnected(connected bool) {
t.isConnected.Store(connected)
wasConnected := t.isConnected.Swap(connected)
if connected {
t.mu.Lock()
t.connectedSince = time.Now()
t.mu.Unlock()
// Increment reconnect count (but not for the initial connection)
if wasConnected || t.reconnectCount.Load() > 0 {
t.reconnectCount.Add(1)
}
}
}
// GetReconnectCount returns the number of reconnections since startup
func (t *Tracker) GetReconnectCount() uint64 {
return t.reconnectCount.Load()
}
// IsConnected returns the current connection status
func (t *Tracker) IsConnected() bool {
return t.isConnected.Load()
@@ -110,6 +120,7 @@ func (t *Tracker) GetStreamMetrics() StreamMetrics {
MessagesPerSec: t.messageRate.Rate1(),
BitsPerSec: t.byteRate.Rate1() * bitsPerByte,
WireBitsPerSec: t.wireByteRate.Rate1() * bitsPerByte,
ReconnectCount: t.reconnectCount.Load(),
}
}
@@ -149,6 +160,8 @@ type StreamMetrics struct {
BitsPerSec float64
// WireBitsPerSec is the rate of bits received on the wire per second (1-minute average)
WireBitsPerSec float64
// ReconnectCount is the number of reconnections since startup
ReconnectCount uint64
}
// RouteMetrics contains route update statistics