完善直播节点监控与边缘代理

This commit is contained in:
admin committed 2026-08-12 21:14:42 +08:00
1 parent 058bb4b99f
commit 20cd99efa4
19 files changed
+401 -47

No files matched your search

+24 -7
View File
@@ -11,11 +11,17 @@ import (
)
type Metrics struct {
CPU float64
Memory float64
Bandwidth float64
ActiveConns int
HlsReaders int
CPU float64
Memory float64
Bandwidth float64
NetworkIn float64
NetworkOut float64
ActiveConns int
HlsReaders int
ViewerCount int
FrameDrops int
PacketLoss int
MediaAvailable bool
}
type Monitor struct {
@@ -54,8 +60,9 @@ func (m *Monitor) Tick() {
} else {
elapsed := now.Sub(m.prevNetTime).Seconds()
if elapsed > 0 {
bytesTotal := (curIn - m.prevNetIn) + (curOut - m.prevNetOut)
metrics.Bandwidth = float64(bytesTotal) * 8 / elapsed / 1e6
metrics.NetworkIn = float64(curIn-m.prevNetIn) * 8 / elapsed / 1e6
metrics.NetworkOut = float64(curOut-m.prevNetOut) * 8 / elapsed / 1e6
metrics.Bandwidth = metrics.NetworkIn + metrics.NetworkOut
}
m.prevNetIn = curIn
m.prevNetOut = curOut
@@ -81,3 +88,13 @@ func (m *Monitor) Snapshot() Metrics {
defer m.mu.RUnlock()
return m.current
}
func (m *Monitor) SetMediaMetrics(media MediaMetrics) {
m.mu.Lock()
m.current.ViewerCount = media.ViewerCount
m.current.HlsReaders = media.ViewerCount
m.current.FrameDrops = media.FrameDrops
m.current.PacketLoss = media.PacketLoss
m.current.MediaAvailable = media.Available
m.mu.Unlock()
}