From 35801ff33a061406ea9e08d2df08174669f4aa30 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sat, 26 Mar 2022 13:01:23 -0700 Subject: [PATCH] Add CPU monitoring to stream health overview --- metrics/healthOverview.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/metrics/healthOverview.go b/metrics/healthOverview.go index 897a5c052..f4822cb35 100644 --- a/metrics/healthOverview.go +++ b/metrics/healthOverview.go @@ -6,6 +6,7 @@ import ( "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/models" + "github.com/owncast/owncast/utils" ) var errorMessages = map[string]string{ @@ -85,6 +86,19 @@ func generateStreamHealthOverview() { } } + // Report high CPU use. + if unhealthyClientCount == 0 && len(metrics.CPUUtilizations) > 2 { + recentCPUUses := metrics.CPUUtilizations[len(metrics.CPUUtilizations)-2:] + values := make([]float64, len(recentCPUUses)) + for i, val := range recentCPUUses { + values[i] = val.Value + } + recentCPUUse := utils.Avg(values) + if recentCPUUse > 90 { + overview.Message = "The CPU usage on your server is over 90%. This may cause video to be provided slower than necessarily, causing buffering for your viewers. Consider increasing the resources available or reducing the number of output variants you made available." + } + } + if unhealthyClientCount == 0 { return }