1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
monitor.go 845 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-05-16 14:37 . code 整合
package system
import "time"
type Monitor struct {
Dur time.Duration `json:"dur" yaml:"dur"`
Diff int64 `json:"diff" yaml:"diff"`
Count int `json:"count" yaml:"count"`
Cpu int `json:"cpu" yaml:"cpu"`
Disk int `json:"disk" yaml:"disk"`
Mem int `json:"mem" yaml:"mem"`
}
func (mon *Monitor) RunMonitor(call func(d *DiskPath, m *MemInfo, cpuPercent float64, flag int)) {
if call == nil {
return
}
if mon.Dur < time.Second {
mon.Dur = time.Second
}
for {
select {
case <-time.After(mon.Dur):
flag := 0
c := CpuPercent()
if int(c) >= mon.Cpu {
flag = 1
}
d := Disk()
if int(d.UsedPercent) >= mon.Disk {
flag |= 2
}
m := Mem()
if int(m.UsedPercent) >= mon.Mem {
flag |= 4
}
if flag > 0 {
call(&d, &m, c, flag)
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.8.26

搜索帮助