diff --git a/pkg/routing/nodestats.go b/pkg/routing/nodestats.go index 999ae9cb3..ac16bb0ef 100644 --- a/pkg/routing/nodestats.go +++ b/pkg/routing/nodestats.go @@ -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]) +} diff --git a/pkg/service/wire_gen.go b/pkg/service/wire_gen.go index 5e9eff96c..45ebcf4d2 100644 --- a/pkg/service/wire_gen.go +++ b/pkg/service/wire_gen.go @@ -29,10 +29,6 @@ import ( "os" ) -import ( - _ "net/http/pprof" -) - // Injectors from wire.go: func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {