mirror of
https://github.com/owncast/owncast.git
synced 2024-11-22 12:49:37 +03:00
769fc3a561
Co-authored-by: Michael Leow <mleow@moneylion.com>
31 lines
583 B
Go
31 lines
583 B
Go
package metrics
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/owncast/owncast/core"
|
|
)
|
|
|
|
// How often we poll for updates
|
|
const viewerMetricsPollingInterval = 5 * time.Minute
|
|
|
|
func startViewerCollectionMetrics() {
|
|
collectViewerCount()
|
|
|
|
for range time.Tick(viewerMetricsPollingInterval) {
|
|
collectViewerCount()
|
|
}
|
|
}
|
|
|
|
func collectViewerCount() {
|
|
if len(Metrics.Viewers) > maxCollectionValues {
|
|
Metrics.Viewers = Metrics.Viewers[1:]
|
|
}
|
|
|
|
count := core.GetStatus().ViewerCount
|
|
value := timestampedValue{
|
|
Value: count,
|
|
Time: time.Now(),
|
|
}
|
|
Metrics.Viewers = append(Metrics.Viewers, value)
|
|
}
|