LoginSignup
1
2

More than 5 years have passed since last update.

Monitのcrond監視

Posted at

[概要]

Monitによるcrondの監視方法をまとめます。

[事前準備]

[作業内容]

監視設定ファイルを作成

通例で、設定ファイル名は「*.rc」とする。

$ sudo vim /etc/monit.d/crond.rc

設定ファイル

if 5 restarts within 5 cycles then unmonitor を設定することによって、再起動を5回やったら諦めてくれるようになります。
何かしらの原因で起動->失敗->起動->失敗 を繰り返されても困るので :sweat_smile:

/etc/monit.d/crond.rc
check process cron with pidfile /var/run/crond.pid
  group system
  start program = "/bin/systemctl start crond"
  stop  program = "/bin/systemctl stop crond"
  if 5 restarts within 5 cycles then unmonitor # 5回の監視中に、5回再起動を実施して監視を停止する

動作確認(CLI)

$ sudo monit status
The Monit daemon 5.14 uptime: 0m

Process 'cron'
  status                            Running
  monitoring status                 Monitored
  pid                               14122
  parent pid                        1
  uid                               0
  effective uid                     0
  gid                               0
  uptime                            4h 2m
  children                          0
  memory                            1.6 MB
  memory total                      1.6 MB
  memory percent                    0.3%
  memory percent total              0.3%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  data collected                    Sun, 27 Nov 2016 10:02:49

System 'server1'
  status                            Running
  monitoring status                 Monitored
  load average                      [0.00] [0.01] [0.05]
  cpu                               0.0%us 0.0%sy 0.0%wa
  memory usage                      81.4 MB [16.6%]
  swap usage                        1.2 MB [0.1%]
  data collected                    Sun, 27 Nov 2016 10:02:49

動作確認(Web)

Web画面から確認してみる
- http://{Monit Server IP}:2812/

monit_process_cron

cron からプロセスの詳細も確認可能です。
画面下の方にある、下記のボタンからプロセスを制御できます。
基本的にroot権限で実行されます。

  • Start service
    • プロセスの起動
  • Stop service
    • プロセスの停止
  • Restart service
    • プロセスの再起動
  • Disable monitoring
    • プロセス監視の停止

monit_process_status_cron

プロセスkillされても起動するか確認

プロセスの確認

$ ps -aef | grep crond
root     31217     1  0 10:08 ?        00:00:00 /usr/sbin/crond -n
vagrant  31316 18008  0 11:05 pts/0    00:00:00 grep --color=auto crond

プロセスをkillする

$ sudo kill -9 31217

プロセスが死んでいることを確認

$ $ ps -aef | grep crond
vagrant  31322 18008  0 11:06 pts/0    00:00:00 grep --color=auto crond

monitからkillされたか確認(CLI)

$ sudo monit status cron
The Monit daemon 5.14 uptime: 1h 4m

Process 'cron'
  status                            Does not exist
  monitoring status                 Monitored
  data collected                    Sun, 27 Nov 2016 11:07:20

monitからkillされたか確認(web)

monit_process_does_not_exist

プロセスが生き返るか確認(CLI)

uptime0m になっており、今さっき起動したのがわかる。

$ sudo monit status cron
The Monit daemon 5.14 uptime: 1h 12m

Process 'cron'
  status                            Running
  monitoring status                 Monitored
  pid                               31354
  parent pid                        1
  uid                               0
  effective uid                     0
  gid                               0
  uptime                            0m
  children                          0
  memory                            1.5 MB
  memory total                      1.5 MB
  memory percent                    0.3%
  memory percent total              0.3%
  cpu percent                       0.0%
  cpu percent total                 0.0%
  data collected                    Sun, 27 Nov 2016 11:15:26

プロセスが生き返るか確認(web)

Uptime0m になっており、今さっき起動したのがわかる。

monit_process_running

[事後確認・作業]

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2