mirror of
https://github.com/livekit/livekit.git
synced 2026-10-26 16:52:25 +00:00
Add API to get latest node stats. (#4589)
This commit is contained in:
1 parent
8efc94eb68
commit
688cc66ed8
2 files changed
+10
-5
No files matched your search
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
@@ -29,7 +30,7 @@ type NodeStats struct {
|
||||
config config.NodeStatsConfig
|
||||
startedAt int64
|
||||
|
||||
lock sync.Mutex
|
||||
lock sync.RWMutex
|
||||
statsHistory []*livekit.NodeStats
|
||||
statsHistoryWritePtr int
|
||||
}
|
||||
@@ -80,3 +81,11 @@ func (n *NodeStats) UpdateAndGetNodeStats() (*livekit.NodeStats, error) {
|
||||
n.statsHistoryWritePtr = (n.statsHistoryWritePtr + 1) % len(n.statsHistory)
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
func (n *NodeStats) GetLatestNodeStats() *livekit.NodeStats {
|
||||
n.lock.RLock()
|
||||
defer n.lock.RUnlock()
|
||||
|
||||
latestPtr := (n.statsHistoryWritePtr - 1 + len(n.statsHistory)) % len(n.statsHistory)
|
||||
return utils.CloneProto(n.statsHistory[latestPtr])
|
||||
}
|
||||
@@ -29,10 +29,6 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
import (
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {
|
||||
|
||||
Reference in new issue
Block a user