owncast/metrics/metrics.go
Gabe Kangas 236f25b772
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
2020-10-02 00:06:14 -07:00

36 lines
649 B
Go

package metrics
import (
"time"
)
// How often we poll for updates
const metricsPollingInterval = 15 * time.Second
type metrics struct {
CPUUtilizations []timestampedValue
RAMUtilizations []timestampedValue
Viewers []timestampedValue
}
// Metrics is the shared Metrics instance
var Metrics *metrics
// Start will begin the metrics collection and alerting
func Start() {
Metrics = new(metrics)
startViewerCollectionMetrics()
for range time.Tick(metricsPollingInterval) {
handlePolling()
}
}
func handlePolling() {
// Collect hardware stats
collectCPUUtilization()
collectRAMUtilization()
// Alerting
handleAlerting()
}