ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

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

2022-07-03 19:03:12  阅读:174  来源: 互联网

标签:Mysql mysql nowtime echo ISHA 监控 scripts 取值 zbx


执行用户: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,mysql,nowtime,echo,ISHA,监控,scripts,取值,zbx
来源: https://www.cnblogs.com/A121/p/16440557.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有