Debuginfo

思考とアウトプット

Monitでプロセス監視

インストールと今回はmemcachedを監視してみます。

# yum install monit

パッケージサイズは236 k。小さくていい^^

設定ファイルは/etc/monit.confを下記のように書く

set httpd port 2812 and use address localhost
    allow localhost  # needed to use monit command
# set daemon mode timeout to 1 minute
set daemon 60
set logfile syslog facility log_daemon
set mailserver 127.0.0.1 # postfix is running on the host
set mail-format {
from: monit@iworlddesigner.com
subject: $HOST : $SERVICE - $EVENT
message: Monit
ACTION  : $ACTION
SERVICE : $SERVICE
at $DATE on $HOST.
DESCRIPTION : $DESCRIPTION
}
set alert mymail@hoge.com but not on { action } # ignore actions
# Include all files from /etc/monit.d/
include /etc/monit.d/*

参考:15分で始めるmonitによるサーバ監視

でmemcachedのエントリを/etc/monit.d/以下に

# cat memcached.conf
check process memcached with pidfile /var/tmp/memcached.pid
every 2 cycle # send alert if issue persist afer 2 cycle (wait for 2min = daemon 60 * 2 until it sends alert
group sheep # group name 
start program = "/usr/bin/memcached -d -P /var/tmp/memcached.pid -m 32 -p 11211"
    as uid <uid> and gid <gid>
stop  program = "/bin/kill `cat /var/tmp/memcached.pid` "
if 5 restarts within 5 cycles then unmonitor

Daemontoolより簡単な気がする!? システム状態を含め色々モニタリングできそうなのでまた次回設定をしようと思います。

Issue experienced

monitコマンドを叩いて以下のようなエラーが出たときは

monit: error connecting to the monit daemon

localhostからのアクセスを許せばいいみたい. 設定ファイルに追加する。

set httpd port 2812
    allow localhost

Reference: http://lists.gnu.org/archive/html/monit-general/2009-08/msg00002.html