我为 Mongrels 编写了一个 monit.d 文件,该文件可在此版本中运行:
check process redmine with pidfile /home/redmine/service/redmine.pid
group webservice
start program = "/usr/bin/mongrel_rails start -p 41328 -e production -d --pid /home/redmine/service/redmine.pid --user redmine --group redmine -a 127.0.0.1 -c /home/redmine/app"
stop program = "/usr/bin/mongrel_rails stop --pid /home/redmine/service/redmine.pid -c /home/redmine/app && rm /home/redmine/service/redmine.pid > /dev/null 2>&1"
if cpu greater 50% for 2 cycles then alert
if cpu greater 80% for 3 cycles then restart
if totalmem greater 60.0 MB for 5 cycles then restart
if loadavg (5min) greater 4 for 8 cycles then restart
if 3 restarts within 5 cycles then timeout
$ Checking monit control file syntax...
$ Control file syntax OK
我还想监控 http 响应,所以我在最后添加了这一行:
if failed port 41328 protocol http with timeout 10 seconds then restart
现在 monit 抱怨:
$ Checking monit control file syntax...
$ /etc/monit.d/redmine:16: Error: exceeded maximum number of program arguments 'http'
$ ERROR: CHECK MONIT CONFIG FILE SYNTAX
如何正确监控端口?
编辑:我终于发现了我的错误:我无意中没有在上面“停止程序”行的末尾添加结束引号。我现在在问题中以及我的服务器上更正了它。
答案1
正确的指令是:
if failed port 41328 protocol http then restart
适用with timeout 10 seconds
于启动程序时超时后导致失败的情况。
谨致问候,
若昂·米格尔·内维斯
答案2
我终于发现了我的错误:我无意中没有在上面“停止程序”行的末尾添加结束引号。我现在在问题中以及我的服务器上更正了它。
现在端口线也可以不发生改变地工作:
if failed port 41328 protocol http with timeout 10 seconds then restart