处理Mysql监控脚本取值异常问题

2022/7/4 2:20:58

本文主要是介绍处理Mysql监控脚本取值异常问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

执行用户:mysql

 

脚本内容:

#! /bin/sh

OSCheckCentOS8=`cat /etc/redhat-release 2>/dev/null |awk '{print $4}' |awk -F"." '{print $1}'`
OSCheckSuse=`cat /etc/issue |awk NR==2 |awk '{print $3}'`
OSCheckKylinV10=`cat /etc/os-release |sed -n '5p' |awk -F '[ "]' '{print $2}'`
MASTER=`ps -ef |grep -v grep |grep -i masterha_manager |wc -l`
ISHA=`cat /mysql/scripts/zabbix/scripts/zbx_mysql_status.py |grep -w "isHA= [0-9]" |awk '{print $NF}'`
ISHA0=0
ISHA1=1
CRONTAB=`crontab -l |grep zbx_mysql_status.py |wc -l`
PYTHON3=`which python3`
nowtime=`date+%Y%m%d%H%M`
logfile=/tmp/zbx_mysql_status.${nowtime}_mysql.log

###################################### isHA Control ############################################
if [ $OSCheckSuse == SUSE ];then
echo "$OSCheckSuse"
echo "$OSCheckSuse" >>logfile
elif [ X$OSCheckKylinV10 == Xkylin ] || [ XOSCheckCentOS8 == X8 ];then
seeds=`cat /mysqldata/myinst1/etc/my.cnf |grep -i loose-group_replication_group_seeds |wc -l`
if [ "$seeds" -eq 1 ];then
sed -i "s/"$ISHA"/"$ISHA1"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
elif [ "$seeds" -eq 0 ];then
lscpu=`lscpu |grep -i "Hypervisor vendor:" |awk '{print $3}'`
if [ "$lscpu" == VMware] || [ "$lscpu" == KVM];then
if [ "$MASTER" -eq 0 ];then
sed -i "s/"$ISHA"/"$ISHA0"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
else
echo "(virtual machine)Please Database teacher verfy: Virtual machine exist masterha_manager processes"
exit 1
fi
fi
else
if [ "$MASTER" -eq 0 ];then
sed -i "s/"$ISHA"/"$ISHA0"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
else
sed -i "s/"$ISHA"/"$ISHA1"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
fi
fi
else
echo "Error!os is not supported!,exit"
echo "Error!os is not supported!,exit" >>logfile
exit 1
fi

###################################### Check Crontab ############################################
if [ $CRONTAB -eq 0 ];then
echo "${nowtime} Crontab Check(0: Not configured crontab;1: configured crontab;)${CRONTAB}"
echo "${nowtime} Crontab Check(0: Not configured crontab;1: configured crontab;)${CRONTAB}" >>logfile
else
crontab -l
crontab -l >>logfile
###################################### Execute Crontab ############################################
MYSQLVALUE=`crontab -l |grep zbx_mysql_status.py |awk -F'[*]+'` '{print $NF}'
touch /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh
echo $MYSQLVALUE > /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh
sh /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh && echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)YES" || echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)NO"
sh /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh && echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)YES" || echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)NO" >> logfile
if



这篇关于处理Mysql监控脚本取值异常问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程