mirror of
https://github.com/owncast/owncast.git
synced 2025-11-02 11:56:57 +08:00
Simple hardware metrics collection + alerting (#115)
* Add CPU and RAM usage alerting * Create basic troubleshooting document to point alerts at * Limit max number of hardware values collected * Save metric value with the point in time it was taken
This commit is contained in:
39
metrics/metrics.go
Normal file
39
metrics/metrics.go
Normal file
@ -0,0 +1,39 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// How often we poll for updates
|
||||
const metricsPollingInterval = 15 * time.Second
|
||||
|
||||
type value struct {
|
||||
Time time.Time
|
||||
Value int
|
||||
}
|
||||
|
||||
type metrics struct {
|
||||
CPUUtilizations []value
|
||||
RAMUtilizations []value
|
||||
}
|
||||
|
||||
// Metrics is the shared Metrics instance
|
||||
var Metrics *metrics
|
||||
|
||||
// Start will begin the metrics collection and alerting
|
||||
func Start() {
|
||||
Metrics = new(metrics)
|
||||
|
||||
for range time.Tick(metricsPollingInterval) {
|
||||
handlePolling()
|
||||
}
|
||||
}
|
||||
|
||||
func handlePolling() {
|
||||
// Collect hardware stats
|
||||
collectCPUUtilization()
|
||||
collectRAMUtilization()
|
||||
|
||||
// Alerting
|
||||
handleAlerting()
|
||||
}
|
||||
Reference in New Issue
Block a user