Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
Surface the % of players represented in metrics
Gabe Kangasc533da273088
diff --git a/controllers/admin/video.go b/controllers/admin/video.goindex ee4407cc19..65f7a69e11 100644--- a/controllers/admin/video.go+++ b/controllers/admin/video.go@@ -29,6 +29,7 @@ func GetVideoPlaybackMetrics(w http.ResponseWriter, r *http.Request) {HighestDownloadRater []metrics.TimestampedValue `json:"maxPlayerBitrate"`AvailableBitrates []int `json:"availableBitrates"`SegmentLength int `json:"segmentLength"`+ Representation int `json:"representation"`}availableBitrates := []int{}@@ -59,6 +60,8 @@ func GetVideoPlaybackMetrics(w http.ResponseWriter, r *http.Request) {maxPlayerBitrate := metrics.GetMaxDownloadRateOverTime()qualityVariantChanges := metrics.GetQualityVariantChangesOverTime()+ representation := metrics.GetPlaybackMetricsRepresentation()+resp := response{AvailableBitrates: availableBitrates,Errors: errors,@@ -73,6 +76,7 @@ func GetVideoPlaybackMetrics(w http.ResponseWriter, r *http.Request) {MedianDownloadRate: medianPlayerBitrate,HighestDownloadRater: maxPlayerBitrate,QualityVariantChanges: qualityVariantChanges,+ Representation: representation,}w.Header().Set("Content-Type", "application/json")diff --git a/metrics/healthOverview.go b/metrics/healthOverview.goindex 90f9c8f6d5..d8d437708d 100644--- a/metrics/healthOverview.go+++ b/metrics/healthOverview.go@@ -4,6 +4,7 @@ import ("fmt""sort"+ "github.com/owncast/owncast/core""github.com/owncast/owncast/core/data""github.com/owncast/owncast/models""github.com/owncast/owncast/utils"@@ -34,6 +35,11 @@ func generateStreamHealthOverview() {overview = errorCountOverview}+ // Determine what percentage of total players are represented in our overview.+ totalPlayerCount := len(core.GetActiveViewers())+ representation := utils.IntPercentage(len(windowedBandwidths), totalPlayerCount)+ overview.Representation = representation+metrics.streamHealthOverview = overview}@@ -146,7 +152,7 @@ func errorCountHealthOverview() *models.StreamHealthOverview {return nil}- healthyPercentage := int(100 - ((float64(clientsWithErrors) / float64(totalNumberOfClients)) * 100))+ healthyPercentage := 100 - utils.IntPercentage(clientsWithErrors, totalNumberOfClients)return &models.StreamHealthOverview{Healthy: healthyPercentage > healthyPercentageValue,diff --git a/metrics/playback.go b/metrics/playback.goindex 280eea9b59..378a1b7fbf 100644--- a/metrics/playback.go+++ b/metrics/playback.go@@ -4,6 +4,7 @@ import ("math""time"+ "github.com/owncast/owncast/core""github.com/owncast/owncast/utils")@@ -326,3 +327,11 @@ func collectQualityVariantChanges() {func GetQualityVariantChangesOverTime() []TimestampedValue {return metrics.qualityVariantChanges}++// GetPlaybackMetricsRepresentation returns what percentage of all known players+// the metrics represent.+func GetPlaybackMetricsRepresentation() int {+ totalPlayerCount := len(core.GetActiveViewers())+ representation := utils.IntPercentage(len(windowedBandwidths), totalPlayerCount)+ return representation+}diff --git a/models/streamHealth.go b/models/streamHealth.goindex a85b8fb33e..83d057fbbd 100644--- a/models/streamHealth.go+++ b/models/streamHealth.go@@ -5,4 +5,5 @@ type StreamHealthOverview struct {Healthy bool `json:"healthy"`HealthyPercentage int `json:"healthPercentage"`Message string `json:"message"`+ Representation int `json:"representation"`}diff --git a/utils/utils.go b/utils/utils.goindex a901362149..f6a32762aa 100644--- a/utils/utils.go+++ b/utils/utils.go@@ -387,3 +387,8 @@ func ShuffleStringSlice(s []string) []string {})return s}++// IntPercentage returns an int percentage of a number.+func IntPercentage(x, total int) int {+ return int(float64(x) / float64(total) * 100)+}