数据库主从监控脚本,数据传到influxdb
#!/bin/bash port=`/usr/sbin/ss -ntlp | grep 3306 | awk '{print $4}' | awk -F":" '{print $2}'` array=($(/usr/local/mysql/bin/mysql -uroot -pUefrwf -e "show slave status\G"|egrep "Running|Seconds_Behind_Master" | awk '{print $2}')) if [ "$port" == "3306" ];then if [ "${array[0]}" == "Yes" ] && [ "${array[1]}" == "Yes" ] ;then num=1 else
num=0 fi fi insert_sql="master_slave,source=mysql_prod_slave1 status=${num},Seconds_Behind_Master=${array[2]}" curl -i -XPOST 'http://10.39.46.5:8086/write?db=fnw_db' --data-binary "$insert_sql"