1
0
Fork 0
mirror of https://github.com/owncast/owncast.git synced 2024-10-28 01:59:38 +01:00

Surface the % of players represented in metrics

This commit is contained in:
Gabe Kangas 2022-03-27 16:27:38 -07:00
parent 9f6151359f
commit 1e19e2a50e
No known key found for this signature in database
GPG key ID: 9A56337728BC81EA
5 changed files with 26 additions and 1 deletions

View file

@ -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")

View file

@ -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,

View file

@ -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
}

View file

@ -5,4 +5,5 @@ type StreamHealthOverview struct {
Healthy bool `json:"healthy"`
HealthyPercentage int `json:"healthPercentage"`
Message string `json:"message"`
Representation int `json:"representation"`
}

View file

@ -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)
}