mysql同步存活检测

mysql 同步存活检测

#!/bin/sh declare -a slave_is slave_is=($(/usr/bin/mysql -uroot -pxxxxxx -e "show slave status\G"|grep Running |awk '{print $2}')) if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ] then echo "OK -slave is running" exit 0 else echo "Critical -slave is error" exit 2 fi
#!/bin/bash user="root" passwd="xxxxxx" slave_sync() { mysql -u$user -p$passwd -e "show slave status\G;"|grep "Running:"|awk -F ':' '{print $2}' } buffer_read_hits() { key_reads=`mysql -u$user -p$passwd -e "show global status like '%key_reads%';"|tail -n 1|awk -F " " '{print $2}'` key_read_requests=`mysql -u$user -p$passwd -e "show global status like '%key_read_requests%';"|tail -n 1|awk -F " " '{print $2}'` awk 'BEGIN{printf "%.2f\n",('1'-'$key_reads'/'$key_read_requests')*100}' } buffer_write_hits() { key_writes=`mysql -u$user -p$passwd -e "show global status like '%key_writes%';"|tail -n 1|awk -F " " '{print $2}'` key_write_requests=`mysql -u$user -p$passwd -e "show global status like '%key_write_requests%';"|tail -n 1|awk -F " " '{print $2}'` awk 'BEGIN{printf "%.2f\n",('1'-'$key_writes'/'$key_write_requests')*100}' } innodb_read_hits() { innodb_reads=`mysql -u$user -p$passwd -e "show global status like '%Innodb_buffer_pool_reads%';"|tail -n 1|awk -F " " '{print $2}'` innodb_requests=`mysql -u$user -p$passwd -e "show global status like '%Innodb_buffer_pool_read_requests%';"|tail -n 1|awk -F " " '{print $2}'` awk 'BEGIN{printf "%.2f\n",('1'-'$innodb_reads'/'$innodb_requests')*100}' } case "$1" in buffer_read_hits) buffer_read_hits ;; buffer_write_hits) buffer_write_hits ;; innodb_read_hits) innodb_read_hits ;; slave_sync) slave_sync ;; *) RETVAL=1 esac exit $RETVAL