mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-09 10:40:10 +08:00
add error detect
This commit is contained in:
@@ -16,12 +16,18 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cpu() string {
|
func cpu() string {
|
||||||
c, _ := C.Percent(0, false)
|
c, err := C.Percent(0, false)
|
||||||
|
if err != nil || len(c) != 1 {
|
||||||
|
return "N/A"
|
||||||
|
}
|
||||||
return fmt.Sprintf("%.1f%%", c[0])
|
return fmt.Sprintf("%.1f%%", c[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func mem() string {
|
func mem() string {
|
||||||
m, _ := M.VirtualMemory()
|
m, err := M.VirtualMemory()
|
||||||
|
if err != nil {
|
||||||
|
return "N/A"
|
||||||
|
}
|
||||||
return fmt.Sprintf("%.1f%%", m.UsedPercent)
|
return fmt.Sprintf("%.1f%%", m.UsedPercent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user