add participant session duration metric (#2801)

This commit is contained in:
Lukas Herman
2024-06-17 17:52:08 -04:00
committed by GitHub
parent 74c7b93170
commit 8a229fda9d
2 changed files with 19 additions and 0 deletions
+6
View File
@@ -164,6 +164,7 @@ type ParticipantImpl struct {
isPublisher atomic.Bool
sessionStartRecorded atomic.Bool
lastActiveAt time.Time
// when first connected
connectedAt time.Time
// timer that's set when disconnect is detected on primary PC
@@ -1375,6 +1376,11 @@ func (p *ParticipantImpl) updateState(state livekit.ParticipantInfo_State) {
return
}
if state == livekit.ParticipantInfo_DISCONNECTED && oldState == livekit.ParticipantInfo_ACTIVE {
prometheus.RecordSessionDuration(int(p.ProtocolVersion()), time.Since(p.lastActiveAt))
} else if state == livekit.ParticipantInfo_ACTIVE {
p.lastActiveAt = time.Now()
}
p.params.Logger.Debugw("updating participant state", "state", state.String())
p.dirty.Store(true)