Skip to content

Commit

Permalink
metrics: fix the panic for reading empty cpu stats (#21864)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 authored Nov 18, 2020
1 parent 23524f8 commit b9ff57c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metrics/cpu_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b9ff57c

Please sign in to comment.