2020-08-27 09:37:32 +02:00
package metrics
import (
log "github.com/sirupsen/logrus"
)
const maxCPUAlertingThresholdPCT = 95
const maxRAMAlertingThresholdPCT = 95
2020-10-02 21:18:08 +02:00
const maxDiskAlertingThresholdPCT = 95
2020-08-27 09:37:32 +02:00
2020-10-02 21:18:08 +02:00
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."
2020-08-27 09:37:32 +02:00
func handleAlerting ( ) {
handleCPUAlerting ( )
handleRAMAlerting ( )
2020-10-02 21:18:08 +02:00
handleDiskAlerting ( )
2020-08-27 09:37:32 +02:00
}
func handleCPUAlerting ( ) {
if len ( Metrics . CPUUtilizations ) < 2 {
return
}
avg := recentAverage ( Metrics . CPUUtilizations )
if avg > maxCPUAlertingThresholdPCT {
2020-10-02 21:18:08 +02:00
log . Errorf ( alertingError , "CPU" , maxCPUAlertingThresholdPCT )
2020-08-27 09:37:32 +02:00
}
}
func handleRAMAlerting ( ) {
if len ( Metrics . RAMUtilizations ) < 2 {
return
}
avg := recentAverage ( Metrics . RAMUtilizations )
if avg > maxRAMAlertingThresholdPCT {
2020-10-02 21:18:08 +02:00
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 )
2020-08-27 09:37:32 +02:00
}
}
2020-10-02 09:06:14 +02:00
func recentAverage ( values [ ] timestampedValue ) int {
2020-11-15 03:39:53 +01:00
return ( values [ len ( values ) - 1 ] . Value + values [ len ( values ) - 2 ] . Value ) / 2
2020-08-27 09:37:32 +02:00
}