add cpu & mem usage info

This commit is contained in:
Jason
2019-08-16 16:49:14 +08:00
parent 1841de7077
commit a4216559c5
2 changed files with 17 additions and 2 deletions

View File

@@ -4,6 +4,9 @@ import (
"fmt"
"strings"
"time"
C "github.com/shirou/gopsutil/cpu"
M "github.com/shirou/gopsutil/mem"
)
var startTime time.Time
@@ -12,6 +15,16 @@ func init() {
startTime = time.Now()
}
func cpu() string {
c, _ := C.Percent(0, false)
return fmt.Sprintf("%.1f%%", c[0])
}
func mem() string {
m, _ := M.VirtualMemory()
return fmt.Sprintf("%.1f%%", m.UsedPercent)
}
func date(t time.Time) string {
return t.Format("Mon Jan 2 15:04:05")
}