暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

mysql 连接数监控

Shubing Wu 2024-12-16
87

用于监控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

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论