Skip to content

Commit dfdeb47

Browse files
committed
Show some basic CPU info
1 parent dc04077 commit dfdeb47

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

greeter.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/dustin/go-humanize"
66
"github.com/hako/durafmt"
77
"github.com/logrusorgru/aurora"
8+
"github.com/shirou/gopsutil/cpu"
89
"github.com/shirou/gopsutil/disk"
910
"github.com/shirou/gopsutil/host"
1011
"github.com/shirou/gopsutil/load"
@@ -36,7 +37,33 @@ func main() {
3637
}
3738

3839
if loadavg, err := load.Avg(); err == nil {
39-
fmt.Printf("%s%.2f, %.2f, %.2f\n", title("Load"), loadavg.Load1, loadavg.Load5, loadavg.Load15)
40+
cpuinfo := ""
41+
42+
if info, err := cpu.Info(); err == nil {
43+
// count cores
44+
cores := make(map[string]bool)
45+
46+
for _, i := range info {
47+
cores[i.CoreID] = true
48+
}
49+
50+
if len(cores) > 1 {
51+
cpuinfo = fmt.Sprintf("%d x ", len(cores))
52+
}
53+
54+
cpuinfo += info[0].ModelName
55+
} else {
56+
cpuinfo = "Error getting CPU info"
57+
}
58+
59+
fmt.Printf(
60+
"%s%.2f, %.2f, %.2f [%s]\n",
61+
title("Load"),
62+
loadavg.Load1,
63+
loadavg.Load5,
64+
loadavg.Load15,
65+
cpuinfo,
66+
)
4067
} else {
4168
fmt.Println(aurora.Red("Error getting loadavg averages: "), err.Error())
4269
}

0 commit comments

Comments
 (0)