From 560df5cade59ae385ef655d88098a2a65345fb7b Mon Sep 17 00:00:00 2001 From: fumiama Date: Wed, 12 Jan 2022 11:39:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20fix(#95):=20aifalse=20error?= =?UTF-8?q?=20unckeck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_ai_false/ai_false.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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)