mirror of
https://github.com/owncast/owncast.git
synced 2024-11-28 19:19:06 +03:00
e042c85f88
* Add metrics for disk usage * Add admin API for hardware metrics * Fix error message alert
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package metrics
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const maxCPUAlertingThresholdPCT = 95
|
|
const maxRAMAlertingThresholdPCT = 95
|
|
const maxDiskAlertingThresholdPCT = 95
|
|
|
|
const alertingError = "The %s utilization of %d%% can cause issues with video generation and delivery. Please visit the documentation at http://owncast.online/docs/troubleshooting/ to help troubleshoot this issue."
|
|
|
|
func handleAlerting() {
|
|
handleCPUAlerting()
|
|
handleRAMAlerting()
|
|
handleDiskAlerting()
|
|
}
|
|
|
|
func handleCPUAlerting() {
|
|
if len(Metrics.CPUUtilizations) < 2 {
|
|
return
|
|
}
|
|
|
|
avg := recentAverage(Metrics.CPUUtilizations)
|
|
if avg > maxCPUAlertingThresholdPCT {
|
|
log.Errorf(alertingError, "CPU", maxCPUAlertingThresholdPCT)
|
|
}
|
|
}
|
|
|
|
func handleRAMAlerting() {
|
|
if len(Metrics.RAMUtilizations) < 2 {
|
|
return
|
|
}
|
|
|
|
avg := recentAverage(Metrics.RAMUtilizations)
|
|
if avg > maxRAMAlertingThresholdPCT {
|
|
log.Errorf(alertingError, "memory", maxRAMAlertingThresholdPCT)
|
|
}
|
|
}
|
|
|
|
func handleDiskAlerting() {
|
|
if len(Metrics.DiskUtilizations) < 2 {
|
|
return
|
|
}
|
|
|
|
avg := recentAverage(Metrics.DiskUtilizations)
|
|
|
|
if avg > maxDiskAlertingThresholdPCT {
|
|
log.Errorf(alertingError, "disk", maxRAMAlertingThresholdPCT)
|
|
}
|
|
}
|
|
|
|
func recentAverage(values []timestampedValue) int {
|
|
return int((values[len(values)-1].Value + values[len(values)-2].Value) / 2)
|
|
}
|