mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +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"`
|
HighestDownloadRater []metrics.TimestampedValue `json:"maxPlayerBitrate"`
|
||||||
AvailableBitrates []int `json:"availableBitrates"`
|
AvailableBitrates []int `json:"availableBitrates"`
|
||||||
SegmentLength int `json:"segmentLength"`
|
SegmentLength int `json:"segmentLength"`
|
||||||
|
Representation int `json:"representation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
availableBitrates := []int{}
|
availableBitrates := []int{}
|
||||||
|
@ -59,6 +60,8 @@ func GetVideoPlaybackMetrics(w http.ResponseWriter, r *http.Request) {
|
||||||
maxPlayerBitrate := metrics.GetMaxDownloadRateOverTime()
|
maxPlayerBitrate := metrics.GetMaxDownloadRateOverTime()
|
||||||
qualityVariantChanges := metrics.GetQualityVariantChangesOverTime()
|
qualityVariantChanges := metrics.GetQualityVariantChangesOverTime()
|
||||||
|
|
||||||
|
representation := metrics.GetPlaybackMetricsRepresentation()
|
||||||
|
|
||||||
resp := response{
|
resp := response{
|
||||||
AvailableBitrates: availableBitrates,
|
AvailableBitrates: availableBitrates,
|
||||||
Errors: errors,
|
Errors: errors,
|
||||||
|
@ -73,6 +76,7 @@ func GetVideoPlaybackMetrics(w http.ResponseWriter, r *http.Request) {
|
||||||
MedianDownloadRate: medianPlayerBitrate,
|
MedianDownloadRate: medianPlayerBitrate,
|
||||||
HighestDownloadRater: maxPlayerBitrate,
|
HighestDownloadRater: maxPlayerBitrate,
|
||||||
QualityVariantChanges: qualityVariantChanges,
|
QualityVariantChanges: qualityVariantChanges,
|
||||||
|
Representation: representation,
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/owncast/owncast/core"
|
||||||
"github.com/owncast/owncast/core/data"
|
"github.com/owncast/owncast/core/data"
|
||||||
"github.com/owncast/owncast/models"
|
"github.com/owncast/owncast/models"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
|
@ -34,6 +35,11 @@ func generateStreamHealthOverview() {
|
||||||
overview = errorCountOverview
|
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
|
metrics.streamHealthOverview = overview
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +152,7 @@ func errorCountHealthOverview() *models.StreamHealthOverview {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
healthyPercentage := int(100 - ((float64(clientsWithErrors) / float64(totalNumberOfClients)) * 100))
|
healthyPercentage := 100 - utils.IntPercentage(clientsWithErrors, totalNumberOfClients)
|
||||||
|
|
||||||
return &models.StreamHealthOverview{
|
return &models.StreamHealthOverview{
|
||||||
Healthy: healthyPercentage > healthyPercentageValue,
|
Healthy: healthyPercentage > healthyPercentageValue,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/owncast/owncast/core"
|
||||||
"github.com/owncast/owncast/utils"
|
"github.com/owncast/owncast/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -326,3 +327,11 @@ func collectQualityVariantChanges() {
|
||||||
func GetQualityVariantChangesOverTime() []TimestampedValue {
|
func GetQualityVariantChangesOverTime() []TimestampedValue {
|
||||||
return metrics.qualityVariantChanges
|
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"`
|
Healthy bool `json:"healthy"`
|
||||||
HealthyPercentage int `json:"healthPercentage"`
|
HealthyPercentage int `json:"healthPercentage"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
Representation int `json:"representation"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -387,3 +387,8 @@ func ShuffleStringSlice(s []string) []string {
|
||||||
})
|
})
|
||||||
return s
|
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