centos 6.5 monit監控inotifywait進程

來源:互聯網
上載者:User

標籤:centos   監控   monit   進程   

最近2天,nagios總是警示,inotifywait進程為0

express_1這台主機有2個rsync指令碼,express_1向express_2同步,開啟後,會有2個inotifywait進程。

每隔幾個小時就會掛掉,需要手動啟動一下。但是這樣太麻煩了,一晚上就發了十幾條nagios警示。


所以我就想用monit來監控inotifywait進程。


建立啟動指令碼

vi /manage/express_monit.sh


#!/bin/bash


case "$1" in

start)

    echo "Starting express..."

    /manage/rsync/rsync_express.sh &

    sleep 1

    ps -aux | grep kuaidihelp_express | head -1 | awk ‘{print $2}‘ > /var/run/express.pid

    ;;


stop)

    echo "Stopping express..."

    kill -9 `cat /var/run/express.pid`

    ;;


restart)

    echo "Stopping express..."

    kill -9 `cat /var/run/express.pid`

    sleep 1

    echo

    echo "Starting express..."

    /manage/rsync/rsync_express.sh &

    sleep 1

    ps -aux | grep kuaidihelp_express | head -1 | awk ‘{print $2}‘ > /var/run/express.pid

    ;;


*)

    echo "Usage: $prog {start|stop|restart}"

    ;;

esac

exit 0


設定許可權

chmod 755 express_monit.sh


安裝monit,最好使用rpm安裝,使用編碼包編譯有問題

yum install -y monit

編輯設定檔

vim /etc/monit.conf

修改檢查時間為3秒以及id檔案路徑和開啟日誌

set daemon  3        # check services at 2-minute intervals


# set logfile syslog facility log_daemon

set logfile /var/log/monit.log


 set idfile /var/.monit.id

 set statefile /var/.monit.state


注釋倒數第3行

# set daemon mode timeout to 1 minute

#set daemon 60


然後啟動monit

/etc/init.d/monit start


進入配置目錄

cd /etc/monit.d/

添加express同步進程監控

vi express


check process express with pidfile /var/run/express.pid

   start program = "/manage/express_monit.sh start"

   stop program = "/manage/express_monit.sh stop"


啟動monit

/etc/init.d/monit start


kill掉inotifywait進程

pkill inotifywait


觀察monit日誌

tail -f /var/log/monit

[CST Apr 20 10:41:07] error    : ‘express‘ process is not running

[CST Apr 20 10:41:07] info     : ‘express‘ trying to restart

[CST Apr 20 10:41:07] info     : ‘express‘ start: /manage/express_monit.sh

[CST Apr 20 10:41:12] info     : ‘express‘ process is running with pid 14139

查看進程是否啟動

[[email protected] ~]# ps -aux | grep ino

Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ

root     14306  0.0  0.0   6344   776 ?        S    10:41   0:00 /usr/local/inotify/bin/inotifywait -mrq --timefmt %d/%m/%y %H:%M --format %T %w%f -e modify,delete,create,attrib /www/kuaidihelp_express/

root     17537  0.0  0.0 103252   864 pts/2    S+   10:47   0:00 grep ino


測試正常。

本文出自 “隕落星空” 部落格,請務必保留此出處http://xiao987334176.blog.51cto.com/2202382/1635954

centos 6.5 monit監控inotifywait進程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.