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