-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
52 lines (49 loc) · 1.29 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"NothinBot/EasyBot"
"fmt"
"regexp"
"strings"
"time"
"github.com/jaypipes/ghw"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/mem"
)
// 运行状态
func checkInfo(ctx *EasyBot.CQMessage) {
match := ctx.RegFindAllStringSubmatch(regexp.MustCompile(`检查身体|运行状态`))
if len(match) > 0 && ctx.IsToMe() {
product, _ := ghw.Product()
cpuInfo, _ := cpu.Info()
memInfo, _ := mem.VirtualMemory()
gpus, _ := ghw.GPU()
cpuUtilization, _ := cpu.Percent(time.Second, false)
s := fmt.Sprintf(
`[NothingBot]
%s %s
%s (%.2f%%)
%.2f / %.2f MB (%.2f%%)
%s
运行时长:%s`,
strings.ReplaceAll(product.Vendor, ", Ltd.", ""), product.Name,
strings.ReplaceAll(cpuInfo[0].ModelName, " ", ""), cpuUtilization[0],
float64(memInfo.Used)/1024.0/1024.0, float64(memInfo.Total)/1024.0/1024.0,
float64(memInfo.Used)/float64(memInfo.Total)*100,
func() (s string) {
for i, gpu := range gpus.GraphicsCards {
name := gpu.DeviceInfo.Product.Name
if !strings.Contains(name, "NVIDIA") && !strings.Contains(name, "AMD") {
break
}
if s != "" {
s += "\n"
}
s += fmt.Sprint("GPU", i, ": ") + name
}
return
}(),
formatTime(int64(bot.GetRunningTime().Seconds())),
)
ctx.SendMsg(s)
}
}