利用Zabbix監控mysql主從

mysql主從監控mysql


#腳本以下,截取主從關鍵字nginx

cat check_mysql_slave.sh 
#!/bin/bash
# declare -a 定義數組,slave_is 會被視爲數組
declare -a slave_is
slave_is=($(/data/mysql/bin/mysql -e "show slave status\G"|grep -E "Slave_IO_Running|Slave_SQL_Running:"|awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ];then
    echo "ok -slave is running"
    exit 0
else
    echo "down -slave is not running"
    exit 2
fi


#zabbix_agentd.conf文件的配置以下:sql

cat zabbix_agentd.conf | grep -v "^#" | grep -v "^$"
LogFile=/tmp/zabbix_agentd.log
EnableRemoteCommands=1
Server=10.74.246.70
ListenPort=10050
ServerActive=10.74.246.70
Hostname=10.74.244.33
AllowRoot=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
UserParameter=tomcat_port,/usr/local/zabbix/share/zabbix/alertscripts/tomcat_port.sh $1
UserParameter=tcp[*],/usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh $1
UserParameter=nginx_port,/usr/local/zabbix/share/zabbix/alertscripts/nginx_port.sh $1
UserParameter=erro_log[*],/usr/local/zabbix/share/zabbix/alertscripts/error_log.sh $1
#mysql主從監控腳本,grep -c "ok",ok出現的次數
UserParameter=mysql.slave,/usr/local/zabbix/share/zabbix/alertscripts/check_mysql_slave.sh | grep -c 'ok'


#建立自定義模板:數組

wKioL1iqlzuwt5IAAAB1cMKGs0M728.png-wh_50

#建立應用集:tomcat

wKiom1iql0qziLLoAAA-Z5gK6yo795.png-wh_50

#建立監控項:bash

wKioL1iql1nRqEVSAACBBxQ-w-4399.png-wh_50

#建立觸發器:tcp

wKioL1iql2qQ4r1yAABWusrBR98896.png-wh_50


#添加mysql-slave監控圖形:ide

wKiom1iql3exr7dfAAByRawHVEs909.png-wh_50


#查看圖形監控效果:
spa

wKioL1iql8fT8n63AACjkApsH4k989.png-wh_50


模板文件下載:3d

相關文章
相關標籤/搜索