Add API to get latest node stats. (#4589)

This commit is contained in:
Raja Subramanian authored and GitHub committed 2026-06-11 19:31:39 +05:30
1 parent 8efc94eb68
commit 688cc66ed8
2 files changed
+10 -5

No files matched your search

+10 -1
View File
@@ -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])
}
-4
View File
@@ -29,10 +29,6 @@ import (
"os"
)
import (
_ "net/http/pprof"
)
// Injectors from wire.go:
func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {