2020-10-02 10:06:14 +03:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2020-10-05 20:07:09 +03:00
|
|
|
"github.com/owncast/owncast/core"
|
2020-10-02 10:06:14 +03:00
|
|
|
)
|
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// How often we poll for updates.
|
2020-11-24 09:21:20 +03:00
|
|
|
const viewerMetricsPollingInterval = 2 * time.Minute
|
2020-10-02 10:06:14 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|