2023-06-10 03:29:02 +03:00
|
|
|
package handlers
|
2022-03-17 03:34:44 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/owncast/owncast/core"
|
|
|
|
"github.com/owncast/owncast/core/data"
|
2023-06-15 03:27:48 +03:00
|
|
|
"github.com/owncast/owncast/services/metrics"
|
2022-03-17 03:34:44 +03:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetVideoPlaybackMetrics returns video playback metrics.
|
2023-06-10 03:29:02 +03:00
|
|
|
func (h *Handlers) GetVideoPlaybackMetrics(w http.ResponseWriter, r *http.Request) {
|
2022-03-17 03:34:44 +03:00
|
|
|
type response struct {
|
2022-03-17 08:49:27 +03:00
|
|
|
Errors []metrics.TimestampedValue `json:"errors"`
|
|
|
|
QualityVariantChanges []metrics.TimestampedValue `json:"qualityVariantChanges"`
|
|
|
|
|
|
|
|
HighestLatency []metrics.TimestampedValue `json:"highestLatency"`
|
|
|
|
MedianLatency []metrics.TimestampedValue `json:"medianLatency"`
|
|
|
|
LowestLatency []metrics.TimestampedValue `json:"lowestLatency"`
|
|
|
|
|
|
|
|
MedianDownloadDuration []metrics.TimestampedValue `json:"medianSegmentDownloadDuration"`
|
|
|
|
MaximumDownloadDuration []metrics.TimestampedValue `json:"maximumSegmentDownloadDuration"`
|
|
|
|
MinimumDownloadDuration []metrics.TimestampedValue `json:"minimumSegmentDownloadDuration"`
|
|
|
|
|
|
|
|
SlowestDownloadRate []metrics.TimestampedValue `json:"minPlayerBitrate"`
|
|
|
|
MedianDownloadRate []metrics.TimestampedValue `json:"medianPlayerBitrate"`
|
|
|
|
HighestDownloadRater []metrics.TimestampedValue `json:"maxPlayerBitrate"`
|
|
|
|
AvailableBitrates []int `json:"availableBitrates"`
|
|
|
|
SegmentLength int `json:"segmentLength"`
|
2022-03-28 02:27:38 +03:00
|
|
|
Representation int `json:"representation"`
|
2022-03-17 03:34:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
availableBitrates := []int{}
|
|
|
|
var segmentLength int
|
|
|
|
if core.GetCurrentBroadcast() != nil {
|
|
|
|
segmentLength = core.GetCurrentBroadcast().LatencyLevel.SecondsPerSegment
|
|
|
|
for _, variants := range core.GetCurrentBroadcast().OutputSettings {
|
|
|
|
availableBitrates = append(availableBitrates, variants.VideoBitrate)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
segmentLength = data.GetStreamLatencyLevel().SecondsPerSegment
|
|
|
|
for _, variants := range data.GetStreamOutputVariants() {
|
|
|
|
availableBitrates = append(availableBitrates, variants.VideoBitrate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errors := metrics.GetPlaybackErrorCountOverTime()
|
2022-03-17 08:49:27 +03:00
|
|
|
medianLatency := metrics.GetMedianLatencyOverTime()
|
|
|
|
minimumLatency := metrics.GetMinimumLatencyOverTime()
|
|
|
|
maximumLatency := metrics.GetMaximumLatencyOverTime()
|
|
|
|
|
|
|
|
medianDurations := metrics.GetMedianDownloadDurationsOverTime()
|
|
|
|
maximumDurations := metrics.GetMaximumDownloadDurationsOverTime()
|
|
|
|
minimumDurations := metrics.GetMinimumDownloadDurationsOverTime()
|
|
|
|
|
2022-03-17 03:34:44 +03:00
|
|
|
minPlayerBitrate := metrics.GetSlowestDownloadRateOverTime()
|
2022-03-17 08:49:27 +03:00
|
|
|
medianPlayerBitrate := metrics.GetMedianDownloadRateOverTime()
|
|
|
|
maxPlayerBitrate := metrics.GetMaxDownloadRateOverTime()
|
2022-03-17 03:34:44 +03:00
|
|
|
qualityVariantChanges := metrics.GetQualityVariantChangesOverTime()
|
|
|
|
|
2022-03-28 02:27:38 +03:00
|
|
|
representation := metrics.GetPlaybackMetricsRepresentation()
|
|
|
|
|
2022-03-17 03:34:44 +03:00
|
|
|
resp := response{
|
|
|
|
AvailableBitrates: availableBitrates,
|
|
|
|
Errors: errors,
|
2022-03-17 08:49:27 +03:00
|
|
|
MedianLatency: medianLatency,
|
|
|
|
HighestLatency: maximumLatency,
|
|
|
|
LowestLatency: minimumLatency,
|
2022-03-17 03:34:44 +03:00
|
|
|
SegmentLength: segmentLength,
|
2022-03-17 08:49:27 +03:00
|
|
|
MedianDownloadDuration: medianDurations,
|
|
|
|
MaximumDownloadDuration: maximumDurations,
|
|
|
|
MinimumDownloadDuration: minimumDurations,
|
2022-03-17 03:34:44 +03:00
|
|
|
SlowestDownloadRate: minPlayerBitrate,
|
2022-03-17 08:49:27 +03:00
|
|
|
MedianDownloadRate: medianPlayerBitrate,
|
|
|
|
HighestDownloadRater: maxPlayerBitrate,
|
2022-03-17 03:34:44 +03:00
|
|
|
QualityVariantChanges: qualityVariantChanges,
|
2022-03-28 02:27:38 +03:00
|
|
|
Representation: representation,
|
2022-03-17 03:34:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
err := json.NewEncoder(w).Encode(resp)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
|
|
|
}
|