2022-03-17 03:34:44 +03:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/owncast/owncast/core"
|
|
|
|
"github.com/owncast/owncast/core/data"
|
|
|
|
"github.com/owncast/owncast/metrics"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetVideoPlaybackMetrics returns video playback metrics.
|
|
|
|
func GetVideoPlaybackMetrics(w http.ResponseWriter, r *http.Request) {
|
|
|
|
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-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()
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
err := json.NewEncoder(w).Encode(resp)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorln(err)
|
|
|
|
}
|
|
|
|
}
|