为了监控程序正常运行,即当程序挂掉时,能够自动重启。
特配置如下:
check process pusher-admin with pidfile /var/run/admin.pid
start program = "/etc/init.d/pusherd start"
stop program = "/etc/init.d/pusherd stop"
if 5 restarts within 5 cycles then timeout
group pusherd
查看是否监控正常,运行命令如下:
[root@pusher-ECM-1-226 pusher]# monit status
The Monit daemon 5.2.5 uptime: 1m
System '127.0.0.1'
status running
monitoring status monitored
load average [0.00] [0.02] [0.05]
cpu 0.0%us 0.0%sy 0.0%wa
memory usage 1731472 kB [10.6%]
swap usage 0 kB [0.0%]
data collected Mon Mar 24 16:44:25 2014
Process 'pusher-admin'
status running
monitoring status monitored
pid 9245
parent pid 1
uptime 5m
children 6
memory kilobytes 978964
memory kilobytes total 983880
memory percent 6.0%
memory percent total 6.0%
cpu percent 0.0%
cpu percent total 0.0%
data collected Mon Mar 24 16:44:25 2014
可以看到,monit已经监控到pusher-admin应用。
注意:在配置pusherd.monit的时候,如果添加上
mode manual
,则需要在/etc/init.d/pusherd中手动去monit这个pusherd应用,即在启动是monit上,在关闭时unmonit,代码示例如下:
start时:
if [ -f /etc/init.d/monit ] ; then
for APPLICATION_TYPE in ${APPLICATION_TYPES}; do
/usr/bin/monit monitor "${APPLICATION_PRODUCT}-${APPLICATION_TYPE}"
done
fi
;;
stop时:
if [ -f /etc/init.d/monit ] ; then
for APPLICATION_TYPE in ${ALL_TYPES[@]}; do
/usr/bin/monit unmonitor "${APPLICATION_PRODUCT}-${APPLICATION_TYPE}"
done
fi
另注:若monit stauts显示某一项服务为not monitored,则可以删除/var/monit/state文件,再重启monit即可。