owncast/metrics/metrics.go

42 lines
879 B
Go
Raw Normal View History

package metrics
import (
"time"
)
2020-11-13 02:14:59 +03:00
// How often we poll for updates.
const metricsPollingInterval = 1 * time.Minute
2020-11-13 02:14:59 +03:00
// CollectedMetrics stores different collected + timestamped values.
type CollectedMetrics struct {
CPUUtilizations []timestampedValue `json:"cpu"`
RAMUtilizations []timestampedValue `json:"memory"`
DiskUtilizations []timestampedValue `json:"disk"`
Viewers []timestampedValue `json:"-"`
}
2020-11-13 02:14:59 +03:00
// Metrics is the shared Metrics instance.
var Metrics *CollectedMetrics
2020-11-13 02:14:59 +03:00
// Start will begin the metrics collection and alerting.
func Start() {
Metrics = new(CollectedMetrics)
go startViewerCollectionMetrics()
handlePolling()
for range time.Tick(metricsPollingInterval) {
handlePolling()
}
}
func handlePolling() {
// Collect hardware stats
collectCPUUtilization()
collectRAMUtilization()
collectDiskUtilization()
// Alerting
handleAlerting()
}