🎨 修改文本格式

This commit is contained in:
Yiwen-Chan 2021-06-30 09:46:42 +08:00
parent 5a76a15e18
commit 2978063cb9

View File

@ -1,6 +1,10 @@
package plugin_i_false /*
暂时只有服务器监控
*/
package plugin_ai_false
import ( import (
"math"
"time" "time"
"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/cpu"
@ -11,30 +15,30 @@ import (
"github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/message"
) )
func GetCpuPercent() float64 {
percent, _ := cpu.Percent(time.Second, false)
return percent[0]
}
func GetMemPercent() float64 {
memInfo, _ := mem.VirtualMemory()
return memInfo.UsedPercent
}
func GetDiskPercent() float64 {
parts, _ := disk.Partitions(true)
diskInfo, _ := disk.Usage(parts[0].Mountpoint)
return diskInfo.UsedPercent
}
func init() { // 插件主体 func init() { // 插件主体
zero.OnFullMatchGroup([]string{"身体检查", "自检", "启动自检", "系统状态"}, zero.AdminPermission). zero.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}, zero.AdminPermission).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text( ctx.SendChain(message.Text(
"人家当前CPU占用率是: ", GetCpuPercent(), "%\n", "* CPU占用率: ", getCpuPercent(), "%\n",
"人家当前RAM占用率是: ", GetMemPercent(), "%\n", "* RAM占用率: ", getMemPercent(), "%\n",
"人家当前硬盘活动率是: ", GetDiskPercent(), "%\n", "* 硬盘活动率: ", getDiskPercent(), "%",
), ),
) )
}) })
} }
func getCpuPercent() float64 {
percent, _ := cpu.Percent(time.Second, false)
return math.Round(percent[0])
}
func getMemPercent() float64 {
memInfo, _ := mem.VirtualMemory()
return math.Round(memInfo.UsedPercent)
}
func getDiskPercent() float64 {
parts, _ := disk.Partitions(true)
diskInfo, _ := disk.Usage(parts[0].Mountpoint)
return math.Round(diskInfo.UsedPercent)
}