diff --git a/plugin_ai_false/ai_false.go b/plugin_ai_false/ai_false.go index 4b7bdf5c..93804715 100644 --- a/plugin_ai_false/ai_false.go +++ b/plugin_ai_false/ai_false.go @@ -43,20 +43,33 @@ func init() { // 插件主体 } func cpuPercent() float64 { - percent, _ := cpu.Percent(time.Second, false) + percent, err := cpu.Percent(time.Second, false) + if err != nil { + return -1 + } return math.Round(percent[0]) } func memPercent() float64 { - memInfo, _ := mem.VirtualMemory() + memInfo, err := mem.VirtualMemory() + if err != nil { + return -1 + } return math.Round(memInfo.UsedPercent) } func diskPercent() string { - parts, _ := disk.Partitions(true) + parts, err := disk.Partitions(true) + if err != nil { + return err.Error() + } msg := "" for _, p := range parts { - diskInfo, _ := disk.Usage(p.Mountpoint) + diskInfo, err := disk.Usage(p.Mountpoint) + if err != nil { + msg += "\n - " + err.Error() + continue + } pc := uint(math.Round(diskInfo.UsedPercent)) if pc > 0 { msg += fmt.Sprintf("\n - %s(%dM) %d%%", p.Mountpoint, diskInfo.Total/1024/1024, pc)