Viewer metrics api (#208)
* Add support for ending the inbound stream. Closes #191 * Add a simple success response to API requests * Add viewers over time API * Move controllers to admin directory
This commit is contained in:
31
metrics/viewers.go
Normal file
31
metrics/viewers.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gabek/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)
|
||||
}
|
||||
Reference in New Issue
Block a user