Skip to content

Commit 408cccf

Browse files
authored
fix: update getLinuxSysInfo to return -1 for CPU and RAM when not applicable
1 parent 442f065 commit 408cccf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/master.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,14 +674,16 @@ func (m *Master) handleInfo(w http.ResponseWriter, r *http.Request) {
674674
// getLinuxSysInfo 获取Linux系统信息
675675
func getLinuxSysInfo() (cpu, ram int) {
676676
if runtime.GOOS != "linux" {
677-
return 0, 0
677+
return -1, -1
678678
}
679679

680680
// CPU使用率:解析/proc/loadavg
681681
if data, err := os.ReadFile("/proc/loadavg"); err == nil {
682682
if fields := strings.Fields(string(data)); len(fields) > 0 {
683683
if load, err := strconv.ParseFloat(fields[0], 64); err == nil {
684684
cpu = min(int(load*100), 100)
685+
} else {
686+
cpu = -1
685687
}
686688
}
687689
}
@@ -699,6 +701,8 @@ func getLinuxSysInfo() (cpu, ram int) {
699701
}
700702
if memTotal > 0 {
701703
ram = min(int((memTotal-memFree)*100/memTotal), 100)
704+
} else {
705+
ram = -1
702706
}
703707
}
704708

0 commit comments

Comments
 (0)