🐛 fix(#95): aifalse error unckeck

This commit is contained in:
fumiama 2022-01-12 11:39:03 +08:00
parent 9f6e361e6e
commit 560df5cade

View File

@ -43,20 +43,33 @@ func init() { // 插件主体
} }
func cpuPercent() float64 { 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]) return math.Round(percent[0])
} }
func memPercent() float64 { func memPercent() float64 {
memInfo, _ := mem.VirtualMemory() memInfo, err := mem.VirtualMemory()
if err != nil {
return -1
}
return math.Round(memInfo.UsedPercent) return math.Round(memInfo.UsedPercent)
} }
func diskPercent() string { func diskPercent() string {
parts, _ := disk.Partitions(true) parts, err := disk.Partitions(true)
if err != nil {
return err.Error()
}
msg := "" msg := ""
for _, p := range parts { 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)) pc := uint(math.Round(diskInfo.UsedPercent))
if pc > 0 { if pc > 0 {
msg += fmt.Sprintf("\n - %s(%dM) %d%%", p.Mountpoint, diskInfo.Total/1024/1024, pc) msg += fmt.Sprintf("\n - %s(%dM) %d%%", p.Mountpoint, diskInfo.Total/1024/1024, pc)