mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-12 02:00:24 +00:00
✨ 添加服务器监控
This commit is contained in:
40
plugin_ai_false/ai_false.go
Normal file
40
plugin_ai_false/ai_false.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package plugin_i_false
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"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() { // 插件主体
|
||||
zero.OnFullMatchGroup([]string{"身体检查", "自检", "启动自检", "系统状态"}, zero.AdminPermission).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.SendChain(message.Text(
|
||||
"人家当前CPU占用率是: ", GetCpuPercent(), "%\n",
|
||||
"人家当前RAM占用率是: ", GetMemPercent(), "%\n",
|
||||
"人家当前硬盘活动率是: ", GetDiskPercent(), "%\n",
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user