使用nagios監(jiān)控被監(jiān)控服務(wù)器上的某一程序,腳本通過查看進程狀態(tài)返回狀態(tài)值,并傳送給nagios,來達到監(jiān)控目的。nagios每個插件監(jiān)控會返回以下狀態(tài)值,我只用到了 0 、1、 2
創(chuàng)新互聯(lián)建站主營西塞山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都App定制開發(fā),西塞山h5微信小程序搭建,西塞山網(wǎng)站營銷推廣歡迎西塞山等地區(qū)企業(yè)咨詢
使用nagios監(jiān)控被監(jiān)控服務(wù)器上的某一程序,腳本通過查看進程狀態(tài)返回狀態(tài)值,并傳送給nagios,來達到監(jiān)控目的。
nagios每個插件監(jiān)控會返回以下狀態(tài)值,我只用到了 0 、1、 2
復(fù)制代碼代碼如下:
#!/bin/bash -x
# Exit values:
# ------------
# 0 OK
# 1 Warning
# 2 Cirital
# 3 Unknown
# Others Unknown
##-------
dfs_process=`ps -ef | grep './dfs client' | grep -v grep`
if [ -z "$dfs_process" ];then
echo "Critical the program of gather is down !!!"
exit 2
fi
process_ppid=`echo $dfs_process|awk '{print $3}'`
process_pid=`echo $dfs_process|awk '{print $2}'`
if [ $process_ppid = 1 ];then
echo 'The process of dfs put back'
exit 1
else
while [ $process_ppid != 1 ]
do
old_process_ppid=$process_ppid
process_ppid=`ps -ef | grep $process_ppid | grep -v $process_pid | grep -v grep | awk '{print $3}'`
process_pid=`ps -ef | grep $old_process_ppid| grep -v $process_pid | grep -v grep|awk '{print $2}'`
done
dfs_pprocess=`ps -ef | grep "$process_pid 1" | grep -v grep`
echo "process of './dfs client' OK ! - Parent process is `echo $dfs_pprocess | awk '{print $8,$9,$10}'`"
exit 0
fi
然后,打開被監(jiān)控端nrpe的配置文件
# vi /usr/local/nagios/etc/nrpe.cfg
添加:
復(fù)制代碼代碼如下:
command[check_dfs]=/usr/local/nagios/libexec/check_dfs.sh
最后,在監(jiān)控端定制監(jiān)控服務(wù)(service.cfg)即可開始監(jiān)控服務(wù)了。