Skip to content

Commit 80d1be4

Browse files
committed
fix: handle case when CPU information is unavailable, returning 0.0 as fallback #193
1 parent 7b01d4a commit 80d1be4

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

reporter/utils/utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ func getDisk(interval int) (uint64, uint64) {
160160

161161
func getCpu(interval int) float64 {
162162
cpuInfo, _ := cpu.Percent(time.Duration(interval)*time.Second, false)
163+
if len(cpuInfo) == 0 {
164+
// If no CPU info available, return 0.0 as fallback
165+
log.Println("Warning: Unable to get CPU usage information, returning 0.0")
166+
return 0.0
167+
}
168+
163169
return math.Round(cpuInfo[0]*10) / 10
164170
}
165171

0 commit comments

Comments
 (0)