【发布时间】:2015-11-01 22:24:11
【问题描述】:
我想使用 monit 杀死一个使用超过 X% CPU 超过 N 秒的进程。
我正在使用stress 生成负载来尝试一个简单的示例。
我的 .monitrc:
check process stress
matching "stress.*"
if cpu usage > 95% for 2 cycles then stop
我开始监视(我检查了 monit -t .monitrc 的语法):
monit -c .monitrc -d 5
我发起压力:
stress --cpu 1 --timeout 60
压力在top 中显示为使用 100 %CPU。
我预计 monit 会在大约 10 秒内消除压力,但压力会成功完成。我做错了什么?
我还尝试了monit procmatch "stress.*",它出于某种原因显示了两个匹配项。也许这很相关?
List of processes matching pattern "stress.*":
stress --cpu 1 --timeout 60
stress --cpu 1 --timeout 60
Total matches: 2
WARNING: multiple processes matched the pattern. The check is FIRST-MATCH based, please refine the pattern
编辑:尝试了 e.lopez 的方法
我不得不从 .monitrc 中删除 start 语句,因为它导致了 monit 错误('stress' failed to start (exit status -1) -- Program /usr/bin/stress timed out 然后是僵尸进程)。
所以手动启动压力:
stress -c 1
stress: info: [8504] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd
.monitrc:
set daemon 5
check process stress
matching "stress.*"
stop program = "/usr/bin/pkill stress"
if cpu > 5% for 2 cycles then stop
启动监控:
monit -Iv -c .monitrc
Starting Monit 5.11 daemon
'xps13' Monit started
'stress' process is running with pid 8504
'stress' zombie check succeeded [status_flag=0000]
'stress' cpu usage check skipped (initializing)
'stress'
'stress' process is running with pid 8504
'stress' zombie check succeeded [status_flag=0000]
'stress' cpu usage check succeeded [current cpu usage=0.0%]
'stress' process is running with pid 8504
'stress' zombie check succeeded [status_flag=0000]
'stress' cpu usage check succeeded [current cpu usage=0.0%]
'stress' process is not running
'stress' trying to restart
'stress' start skipped -- method not defined
Monit 看到正确的进程(pid 匹配),但看到 0% 的使用率(压力是每个顶部 100% 使用 1 个 cpu)。我手动消除了压力,这是当 monit 说进程没有运行时(最后,上面)。因此,monit 可以正常监控进程,但没有看到正确的 cpu 使用情况。
有什么想法吗?
【问题讨论】:
标签: monit ubuntu-15.04