Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Fix CPU usage collection panic with default zero value. Closes #2423

Gabe Kangas8de1154aa1ae
diff --git a/metrics/hardware.go b/metrics/hardware.go
index 5959440062..9a642fa737 100644
--- a/metrics/hardware.go
+++ b/metrics/hardware.go
@@ -24,7 +24,14 @@ func collectCPUUtilization() {
return
}
- metricValue := TimestampedValue{time.Now(), v[0]}
+ // Default to zero but try to use the cumulative values of all the CPUs
+ // if values exist.
+ value := 0.0
+ if len(v) > 0 {
+ value = v[0]
+ }
+
+ metricValue := TimestampedValue{time.Now(), value}
metrics.CPUUtilizations = append(metrics.CPUUtilizations, metricValue)
cpuUsage.Set(metricValue.Value)
}