nagios监控haproxy(借助脚本)
修改后的脚本如下(需添加指示灯的状态)
# vi haproxy.sh
#!/bin/bash
Port=`netstat -ntpl | grep haproxy | awk -F[:" "]+ '{print $5}'`
if [ $Port == "1080" ];then
echo "OK - haproxy is running"
exit 0
else
echo "CRITICAL - haproxy is down"
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
exit 2
fi
:wq
注:0 指的是状态灯绿灯,2指的是红灯,黄灯不用 并且宕了之后再次check时就能自动重启
# cp haproxy.sh /usr/local/nagios/libexec
# chmod +x /usr/local/nagios/libexec/haproxy.sh
# mount /dev/cdrom /media/cdrom
# rpm -ivh sudo-1.6.9pl7-3.el5.i386.rpm
# visudo
#Defaults requiretty (注释掉)
nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/haproxy.sh (多个脚本的话设置多行)
:wq
# su - nagios -c 'sudo /usr/local/nagios/libexec/haproxy.sh' (看看执行是否成功)
# vi /usr/local/nagios/etc/nrpe.cfg
command[check_haproxy]=/usr/bin/sudo /usr/local/nagios/libexec/haproxy.sh
:wq
# killall nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# vi /usr/local/nagios/etc/objects/ming.cfg
define service{
use generic-service
host_name ming
service_description HA
check_command check_nrpe!check_haproxy
}
:wq
# service nagios restart
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。