mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 12:18:02 +03:00
Surface the % of players represented in metrics
This commit is contained in:
parent
9f6151359f
commit
1e19e2a50e
5 changed files with 26 additions and 1 deletions
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -5,4 +5,5 @@ type StreamHealthOverview struct {
|
|||
Healthy bool `json:"healthy"`
|
||||
HealthyPercentage int `json:"healthPercentage"`
|
||||
Message string `json:"message"`
|
||||
Representation int `json:"representation"`
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue