Unverified Commit b9ff57c5 authored by gary rong's avatar gary rong Committed by GitHub

metrics: fix the panic for reading empty cpu stats (#21864)

parent 23524f89
......@@ -31,6 +31,10 @@ func ReadCPUStats(stats *CPUStats) {
log.Error("Could not read cpu stats", "err", err)
return
}
if len(timeStats) == 0 {
log.Error("Empty cpu stats")
return
}
// requesting all cpu times will always return an array with only one time stats entry
timeStat := timeStats[0]
stats.GlobalTime = int64((timeStat.User + timeStat.Nice + timeStat.System) * cpu.ClocksPerSec)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment