用zabbix監控mysql的主從複製

czxin788發表於2015-07-30

用zabbix監控mysql的主從複製

在要監控的伺服器設定如下指令碼
[root@zabbixsrvbjdb04 ~]# cat /data/script/monitor.sh

#!/bin/sh

# check_mysql_slave status

#修改網路卡資訊

ip=eth0  

mysql_binfile=/usr/local/mysql/bin/mysql

#監控使用的賬號資訊

mysql_user=monitor 

mysql_pass='monitor123567'  

#sock

mysql_sockfile=/holiday/mariadb/mysql.sock

datetime=`date +"%Y-%m-%d/%H:%M:%S"`   

#監控狀態日誌檔案,自行定義

mysql_slave_logfile=/holiday/moniter/check_mysql_slave.log  

#監控狀態輸出檔案,監控檔案

mysql_slave_status=/home/monitor/slavestatus 

#獲取IP

slave_ip=`ifconfig $ip|grep "inet addr" | awk -F[:" "]+ '{print $4}'`

#獲取slave狀態

status=$($mysql_binfile -u$mysql_user -p$mysql_pass -P3307 -e "show slave status\G" | grep -i "running")

Slave_IO_Running=`echo $status | grep Slave_IO_Running | awk ' {print $2}'`

Slave_SQL_Running=`echo $status | grep Slave_SQL_Running | awk '{print $2}'`

echo $Slave_IO_Running

echo $Slave_SQL_Running

#判斷

if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ]

then 

      echo "Slave is Running!"

      echo 1 > $mysql_slave_status

else

        echo 0 > $mysql_slave_status

        echo " $datetime $slave_ip Slave is not running!" >> $mysql_slave_logfile

     

fi




設定任務執行計劃:
[root@zabbixsrvbjdb01 ~]# crontab -l
*/1 * * * * /usr/sbin/ntpdate 10.2.43.16
*/10 * * * * /data/script/monitor.sh


然後在zabbix agent裡面設定的配置檔案末尾新增如下引數:
 #cat /usr/local/zabbixagent/conf/zabbix_agentd.conf


UserParameter=slavestatus,cat /home/monitor/slavestatus
UserParameter= breads,sar -b 1 5|tail -n 1|awk '{print $4}'
UserParameter= bwrtns,sar -b 1 5|tail -n 1|awk '{print $5}'

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28916011/viewspace-1756334/,如需轉載,請註明出處,否則將追究法律責任。

相關文章