用于监控mysql的连接数情况
vi connect_check.sh
#!/bin/bash
# function:Mysql connections Check
# author:wu
# date:2023-11-16
con=`mysql -u user -pxxxxx -N -e "SELECT
@Threads_connected := (select VARIABLE_VALUE from performance_schema.GLOBAL_STATUS where variable_name ='Threads_connected') as Threads_connected,
ROUND(@Threads_connected / VARIABLE_VALUE*100,2) AS ratio
FROM
performance_schema.global_variables where variable_name ='max_connections'"`
ratio=$(echo $con |awk -F' ' '{print $2}')
content=`mysql -u user -pxxxxxx -N -e "
select * from performance_schema.GLOBAL_STATUS where variable_name in('Max_used_connections','Max_used_connections_time','Threads_connected')
union
select * from performance_schema.global_variables where variable_name ='max_connections'"`
if [[ $ratio < "90" ]];then
echo [`date +"%F %T"`] the connections $ratio% is ok >> log.log
else
echo [`date +"%F %T"`] the connections is error:$ratio% $content >> log.log
fi
exit




