Analytics events + stats (#187)
* events * bump * update incoming stats * publisher stats * outgoing rtcp * stats * remove unnecessary struct * merge mediaTrack * put comment back
This commit is contained in:
+85
-25
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/livekit/protocol/logger"
|
||||
livekit "github.com/livekit/protocol/proto"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
@@ -20,7 +21,11 @@ func (t *TelemetryService) RoomStarted(ctx context.Context, room *livekit.Room)
|
||||
Room: room,
|
||||
})
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_ROOM_CREATED,
|
||||
Timestamp: ×tamppb.Timestamp{Seconds: room.CreationTime},
|
||||
Room: room,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) RoomEnded(ctx context.Context, room *livekit.Room) {
|
||||
@@ -31,10 +36,18 @@ func (t *TelemetryService) RoomEnded(ctx context.Context, room *livekit.Room) {
|
||||
Room: room,
|
||||
})
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_ROOM_ENDED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
RoomSid: room.Sid,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) ParticipantJoined(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo) {
|
||||
t.Lock()
|
||||
t.workers[participant.Sid] = NewStatsWorker(t, room.Sid, participant.Sid)
|
||||
t.Unlock()
|
||||
|
||||
prometheus.AddParticipant()
|
||||
|
||||
t.notifyEvent(ctx, &livekit.WebhookEvent{
|
||||
@@ -43,7 +56,11 @@ func (t *TelemetryService) ParticipantJoined(ctx context.Context, room *livekit.
|
||||
Participant: participant,
|
||||
})
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_PARTICIPANT_JOINED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
Participant: participant,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo) {
|
||||
@@ -62,46 +79,71 @@ func (t *TelemetryService) ParticipantLeft(ctx context.Context, room *livekit.Ro
|
||||
Participant: participant,
|
||||
})
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_PARTICIPANT_LEFT,
|
||||
Timestamp: timestamppb.Now(),
|
||||
ParticipantId: participant.Sid,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) TrackPublished(participantID, identity string, track *livekit.TrackInfo, buff *buffer.Buffer) {
|
||||
t.Lock()
|
||||
if t.workers[participantID] == nil {
|
||||
t.workers[participantID] = NewStatsWorker(func(diff *buffer.Stats) {
|
||||
t.HandleIncomingRTP(participantID, identity, diff)
|
||||
})
|
||||
}
|
||||
t.workers[participantID].AddBuffer(buff)
|
||||
t.Unlock()
|
||||
|
||||
func (t *TelemetryService) TrackPublished(participantID string, track *livekit.TrackInfo) {
|
||||
prometheus.AddPublishedTrack(track.Type.String())
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_TRACK_PUBLISHED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
ParticipantId: participantID,
|
||||
Track: track,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) TrackUnpublished(participantID, identity string, track *livekit.TrackInfo, ssrc uint32) {
|
||||
func (t *TelemetryService) AddUpTrack(participantID string, buff *buffer.Buffer) {
|
||||
t.RLock()
|
||||
if w := t.workers[participantID]; w != nil {
|
||||
w := t.workers[participantID]
|
||||
t.RUnlock()
|
||||
if w != nil {
|
||||
w.AddBuffer(buff)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TelemetryService) TrackUnpublished(participantID string, track *livekit.TrackInfo, ssrc uint32) {
|
||||
t.RLock()
|
||||
w := t.workers[participantID]
|
||||
t.RUnlock()
|
||||
if w != nil {
|
||||
w.RemoveBuffer(ssrc)
|
||||
}
|
||||
t.RUnlock()
|
||||
|
||||
prometheus.SubPublishedTrack(track.Type.String())
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_TRACK_UNPUBLISHED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
ParticipantId: participantID,
|
||||
TrackId: track.Sid,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) TrackSubscribed(participantID, identity string, track *livekit.TrackInfo) {
|
||||
func (t *TelemetryService) TrackSubscribed(participantID string, track *livekit.TrackInfo) {
|
||||
prometheus.AddSubscribedTrack(track.Type.String())
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_TRACK_SUBSCRIBED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
ParticipantId: participantID,
|
||||
TrackId: track.Sid,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) TrackUnsubscribed(participantID, identity string, track *livekit.TrackInfo) {
|
||||
func (t *TelemetryService) TrackUnsubscribed(participantID string, track *livekit.TrackInfo) {
|
||||
prometheus.SubSubscribedTrack(track.Type.String())
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_TRACK_UNSUBSCRIBED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
ParticipantId: participantID,
|
||||
TrackId: track.Sid,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) RecordingStarted(ctx context.Context, recordingID string, req *livekit.StartRecordingRequest) {
|
||||
@@ -113,7 +155,11 @@ func (t *TelemetryService) RecordingStarted(ctx context.Context, recordingID str
|
||||
},
|
||||
})
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_RECORDING_STARTED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
RecordingId: recordingID,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) RecordingEnded(res *livekit.RecordingResult) {
|
||||
@@ -122,7 +168,11 @@ func (t *TelemetryService) RecordingEnded(res *livekit.RecordingResult) {
|
||||
RecordingResult: res,
|
||||
})
|
||||
|
||||
// TODO: analytics service
|
||||
t.sendEvent(&livekit.AnalyticsEvent{
|
||||
Type: livekit.AnalyticsEventType_RECORDING_ENDED,
|
||||
Timestamp: timestamppb.Now(),
|
||||
RecordingId: res.Id,
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) notifyEvent(ctx context.Context, event *livekit.WebhookEvent) {
|
||||
@@ -136,3 +186,13 @@ func (t *TelemetryService) notifyEvent(ctx context.Context, event *livekit.Webho
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (t *TelemetryService) sendEvent(event *livekit.AnalyticsEvent) {
|
||||
if t.analyticsEnabled {
|
||||
if err := t.events.Send(&livekit.AnalyticsEvents{
|
||||
Events: []*livekit.AnalyticsEvent{event},
|
||||
}); err != nil {
|
||||
logger.Errorw("failed to send event", err, "eventType", event.Type.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user