Add API to get latest node stats. (#4589)
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
"github.com/livekit/protocol/utils"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||||
@@ -29,7 +30,7 @@ type NodeStats struct {
|
|||||||
config config.NodeStatsConfig
|
config config.NodeStatsConfig
|
||||||
startedAt int64
|
startedAt int64
|
||||||
|
|
||||||
lock sync.Mutex
|
lock sync.RWMutex
|
||||||
statsHistory []*livekit.NodeStats
|
statsHistory []*livekit.NodeStats
|
||||||
statsHistoryWritePtr int
|
statsHistoryWritePtr int
|
||||||
}
|
}
|
||||||
@@ -80,3 +81,11 @@ func (n *NodeStats) UpdateAndGetNodeStats() (*livekit.NodeStats, error) {
|
|||||||
n.statsHistoryWritePtr = (n.statsHistoryWritePtr + 1) % len(n.statsHistory)
|
n.statsHistoryWritePtr = (n.statsHistoryWritePtr + 1) % len(n.statsHistory)
|
||||||
return stats, nil
|
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"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
import (
|
|
||||||
_ "net/http/pprof"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Injectors from wire.go:
|
// Injectors from wire.go:
|
||||||
|
|
||||||
func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {
|
func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*LivekitServer, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user