check process mysql with pidfile /var/run/mysqld/mysqld.pid
every 1 cycle
start program="/etc/rc.d/init.d/mysqld start" stop program="/etc/rc.d/init.d/mysqld stop"if failed
host localhost port 3306 protocol mysql
with timeout 15 seconds for3times within 4 cycles
then restart$if failed
unixsocket /var/run/mysqld/mysqld.sock protocol mysql
for3times within 4 cycles
then restart$if5 restarts within 5 cycles then timeout
“mysqld.pid” ファイルを1サイクル(今回の設定では 120秒 * 1 = 60秒)毎に監視し、存在しなければ MySQL サーバを再起動する。
TCP ポート 3306 への接続が4回中3回15秒のタイムアウトで失敗する場合は、 MySQL サーバを再起動する。
# monit status
The Monit daemon 5.9 uptime: 1m
Process 'mysqld'
status Running
monitoring status Monitored
pid 5258
parent pid 4953
uid 999
effective uid 999
gid 1001
uptime 32m
children 0
memory kilobytes 157.3 MB
memory kilobytes total 157.3 MB
memory percent 7.8%
memory percent total 7.8%
cpu percent 0.0%
cpu percent total 0.0%
unix socket response time 0.000s to /var/run/mysqld/mysqld.sock [MYSQL]
port response time 0.001s to localhost:3306 [MYSQL via TCP]
data collected Wed, 21 Dec 2016 22:05:55
System 'foo.bar.com'
status Running
monitoring status Monitored
load average [0.63] [0.31] [0.24]
cpu 0.0%us 0.0%sy 0.0%wa
memory usage 663.4 MB [33.2%]
swap usage 0.0 B [0.0%]
data collected Wed, 21 Dec 2016 22:05:55
status が Running であれば、「監視中」である。
monit summary だと status だけを確認できる。
7. 個別監視の停止・起動
個別に監視を停止・起動するには以下のようにする。
12
# monit stop xxxx
# monit start xxxx
8. グループ単位での監視の停止・起動
個別の設定ファイル内で group xxxx のように記述していれば、xxxx グループの単位で監視を停止・起動することができる。