Sfoglia il codice sorgente

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

gary rong 5 anni fa
parent
commit
b9ff57c59e
1 ha cambiato i file con 4 aggiunte e 0 eliminazioni
  1. 4 0
      metrics/cpu_enabled.go

+ 4 - 0
metrics/cpu_enabled.go

@@ -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)