monit を使ったサーバ監視 id:fujya
突然ですが、 こんな経験ありませんか? プロセスの暴走    ↓ メモリー大喰い    ↓ OOM Killer 発動    ↓ sshd が殺される
とりあえず暴走終わったぽいけど・・・ sshd 殺されてるからサーバに入れない ネットワーク KVM を導入してない データセンターに行くしか無い まぢ面倒
monit 導入してれば大丈夫!!
monit がある生活なら プロセスの暴走    ↓ メモリー大喰い    ↓ OOM Killer 発動    ↓ sshd が殺される    ↓ monit が sshd が死んだことを検知    ↓ monit が sshd を再起動    ↓ データセンター行かなくて良い!!(やったね♪) new! new! new!
総合監視デーモン ライセンス: GPLv2 動作環境 : Linux,BSD,SunOS/Solaris         32bit/64bit 最新版: 5.1.1(23 February 2010 updated) monit とは
monit で出来る事 監視項目に対して条件を設定 条件にマッチしたら指定したアクションを実行
監視項目 プロセス (pid/ppid) ファイルシステム ディスク容量( space / i-node ) ファイルサイズ ファイルパーミッション uid/gid checksum タイムスタンプ ファイル内容パターンマッチ ロードアベレージ メモリ使用量 レスポンス内容パターンマッチ (send/expect も可能 )
アクション 起動、再起動 アラートメールを送信する ユーザスクリプトを実行する 監視の停止
Example 1 #  監視間隔 set daemon 60  # log format set logfile syslog facility log_daemon  #  メールサーバの指定 (SMTP で接続 ) set mailserver  mailserver.server.domain,  # primary mailserver 10.8.15.100                     # secondary mailserver #  アラートメールのフォーマット set mail-format { from: monit@shanon.co.jp subject: $HOST : $SERVICE - $EVENT message: Monit  ACTION  : $ACTION SERVICE : $SERVICE at $DATE on $HOST.  DESCRIPTION : $DESCRIPTION } #  アラート送信先 set alert alert@alert.adder set alert alert-mobile@alert.adder not on { INSTANCE } #  コンフィグの include include /etc/monit.d/*.conf
Example 2 # 1min のロードアベレージが 5 回中 3 回5を超えていたらアラート送信 check system localhost.localdomain if loadavg (1min) > 5 for 3 times within 5 cycles then alert # http://localhost:8080/services/name へリクエストし、レスポンス内容に OK が3回連続で入ってなかったら # /path/to/program を apache 権限で実行して [email_address] にメール送信 check host  any_services_name address localhost if failed url http://localhost:8080/services/name and content = 'OK' 3 times within 3 cycle then exec "/path/to/program" as uid apache and gid apache alert alert@alert.mobile.addr ÷
いろんな使い方ができます ロードアベレージの監視  ->  アラート デーモンの監視  ->  自動再起動 メモリリークの監視  ->  自動メモリ解放 ファイルサイズの監視  -> logrotate Nagios に http://example.com/nagios/check を定期的に叩かせて、 example.com の monit で nagios/check のタイムスタンプを監視( Nagios が動いている事を監視)  ->  アラート
まとめ  -monit 特徴 - 監視項目が幅広い 自動再起動 オープンソース ドキュメントが超豊富(これ超重要) WEB GUI 有り monit 集中管理用 m/monit もあるよ (使ったこと無い)
ご清聴ありがとうございました

Monit

  • 1.
  • 2.
    突然ですが、 こんな経験ありませんか? プロセスの暴走   ↓ メモリー大喰い    ↓ OOM Killer 発動    ↓ sshd が殺される
  • 3.
    とりあえず暴走終わったぽいけど・・・ sshd 殺されてるからサーバに入れないネットワーク KVM を導入してない データセンターに行くしか無い まぢ面倒
  • 4.
  • 5.
    monit がある生活なら プロセスの暴走   ↓ メモリー大喰い    ↓ OOM Killer 発動    ↓ sshd が殺される    ↓ monit が sshd が死んだことを検知    ↓ monit が sshd を再起動    ↓ データセンター行かなくて良い!!(やったね♪) new! new! new!
  • 6.
    総合監視デーモン ライセンス: GPLv2動作環境 : Linux,BSD,SunOS/Solaris         32bit/64bit 最新版: 5.1.1(23 February 2010 updated) monit とは
  • 7.
    monit で出来る事 監視項目に対して条件を設定条件にマッチしたら指定したアクションを実行
  • 8.
    監視項目 プロセス (pid/ppid)ファイルシステム ディスク容量( space / i-node ) ファイルサイズ ファイルパーミッション uid/gid checksum タイムスタンプ ファイル内容パターンマッチ ロードアベレージ メモリ使用量 レスポンス内容パターンマッチ (send/expect も可能 )
  • 9.
    アクション 起動、再起動 アラートメールを送信するユーザスクリプトを実行する 監視の停止
  • 10.
    Example 1 # 監視間隔 set daemon 60 # log format set logfile syslog facility log_daemon # メールサーバの指定 (SMTP で接続 ) set mailserver mailserver.server.domain, # primary mailserver 10.8.15.100                    # secondary mailserver # アラートメールのフォーマット set mail-format { from: monit@shanon.co.jp subject: $HOST : $SERVICE - $EVENT message: Monit ACTION : $ACTION SERVICE : $SERVICE at $DATE on $HOST. DESCRIPTION : $DESCRIPTION } # アラート送信先 set alert alert@alert.adder set alert alert-mobile@alert.adder not on { INSTANCE } # コンフィグの include include /etc/monit.d/*.conf
  • 11.
    Example 2 #1min のロードアベレージが 5 回中 3 回5を超えていたらアラート送信 check system localhost.localdomain if loadavg (1min) > 5 for 3 times within 5 cycles then alert # http://localhost:8080/services/name へリクエストし、レスポンス内容に OK が3回連続で入ってなかったら # /path/to/program を apache 権限で実行して [email_address] にメール送信 check host any_services_name address localhost if failed url http://localhost:8080/services/name and content = 'OK' 3 times within 3 cycle then exec "/path/to/program" as uid apache and gid apache alert alert@alert.mobile.addr ÷
  • 12.
    いろんな使い方ができます ロードアベレージの監視 -> アラート デーモンの監視 -> 自動再起動 メモリリークの監視 -> 自動メモリ解放 ファイルサイズの監視 -> logrotate Nagios に http://example.com/nagios/check を定期的に叩かせて、 example.com の monit で nagios/check のタイムスタンプを監視( Nagios が動いている事を監視) -> アラート
  • 13.
    まとめ -monit特徴 - 監視項目が幅広い 自動再起動 オープンソース ドキュメントが超豊富(これ超重要) WEB GUI 有り monit 集中管理用 m/monit もあるよ (使ったこと無い)
  • 14.