monitで監視、アラート通知


参考

インストール

  • 依存パッケージがほぼない。
sudo apt-get install -y monit

設定

include /etc/monit/conf.d/*

  • /etc/monit/monitrc は編集しない。最終行で上記があるので外出しする。
/etc/monit/conf.d/check_hosts.conf
#------------
# メール設定
#------------
# 指定しないとメールが飛ばなかった
set mailserver localhost

# アラート通知先
set alert [email protected]


#--------------
# httpサーバ設定
#--------------
# monitのステータスをwebで見れる。localhostのみ許可
set httpd port 2812 and
   use address localhost
   allow localhost


#--------------
# 監視対象
#--------------
# http://server1.hoge.jp/ が停止・復旧したらメール通知
check host server1 with address server1.hoge.jp
    if failed url http://server1.hoge.jp/
    then alert

# server2.hoge.jp:22 が停止・復旧したらメール通知
check host server2 with address server2.hoge.jp
    if failed port 22
    then alert

サービス起動

syntaxチェック
sudo monit -t
monit再起動
sudo systemctl restart monit

監視間隔

set daemon 120

  • 2分おきに監視(初期値)