Skip to content

Commit b9ff57c

Browse files
authored
metrics: fix the panic for reading empty cpu stats (#21864)
1 parent 23524f8 commit b9ff57c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

metrics/cpu_enabled.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func ReadCPUStats(stats *CPUStats) {
3131
log.Error("Could not read cpu stats", "err", err)
3232
return
3333
}
34+
if len(timeStats) == 0 {
35+
log.Error("Empty cpu stats")
36+
return
37+
}
3438
// requesting all cpu times will always return an array with only one time stats entry
3539
timeStat := timeStats[0]
3640
stats.GlobalTime = int64((timeStat.User + timeStat.Nice + timeStat.System) * cpu.ClocksPerSec)

0 commit comments

Comments
 (0)