临时监控mysql数据库连接数以及主从同步状态

因为公司项目紧急召唤,一个未上线的系统需要临时给领导演示,项目组负责人为了不影响演示效果,临时安排了我们几个同事对系统进行人肉监控。数据库层面主要监控数据库日志,数据库连接数,主从同步状态,系统资源负载等。

数据库连接数监控

# cat check_connects2.sh 
#!/bin/bash
while true
do
        sleep 5
        date
        result=$(mysql -uroot -ppwd -e "SHOW STATUS LIKE 'Threads_connected';" | awk '{print $2}')
        echo "当前MySQL连接数为:$result"
    
done

数据库主从同步状态监控

# cat check_slave2.sh 
#!/bin/bash
while true
do
        sleep 5
        date
        bash /root/scripts/check_slave3.sh
done

# cat check_slave3.sh 
#!/bin/bash
 
mysql -uroot -ppwd -e "show slave status\G" | grep -E 'Slave_IO_Running|Slave_SQL_Running' |grep -v Slave_SQL_Running_State

效果

# /root/scripts/check_connects2.sh 
Sat Aug 17 16:09:44 CST 2024
mysql: [Warning] Using a password on the command line interface can be insecure.
当前MySQL连接数为:Value
146
Sat Aug 17 16:09:49 CST 2024
mysql: [Warning] Using a password on the command line interface can be insecure.
当前MySQL连接数为:Value
146
Sat Aug 17 16:09:54 CST 2024
mysql: [Warning] Using a password on the command line interface can be insecure.
当前MySQL连接数为:Value
146
# ./check_slave2.sh 
Sat Aug 17 16:11:47 CST 2024
mysql: [Warning] Using a password on the command line interface can be insecure.
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
Sat Aug 17 16:11:52 CST 2024
mysql: [Warning] Using a password on the command line interface can be insecure.
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
Sat Aug 17 16:11:57 CST 2024
mysql: [Warning] Using a password on the command line interface can be insecure.
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值