一 简介 今天咱们来聊聊MGR的监控
二 监控 方面: 1 节点mysql进程监控
2 节点mysql复制进程的监控
3 节点是否为主的监控
4 节点延迟事务的监控
三 方法:
一 经过proxysql对MGR功能的支持,采用其中的sql就可以创建常用的监控表
1 相关表:gr_member_routing_candidate_status
viable_candidate //节点的状态,当复制停止时此值会异常
read_only // 主节点时此值会为OFF
transactions_behind //可以理解为等待应用事务的延迟
transactions_to_cert//可以理解为等待通过验证的事务
二 实现的一些原理
1 SELECT Received_transaction_set FROM performance_schema.replication_connection_status WHERE Channel_name = 'group_replication_applier'//接收到的GTID
select @@global.GTID_EXECUTED;//执行的GTID
接收到的-执行的 就是延迟了 也即是 transactions_behind
2 SELECT (SELECT GROUP_CONCAT(variable_value) FROM
performance_schema.global_variables WHERE variable_name IN ('read_only',
'super_read_only')) != 'OFF,OFF'), 'YES', 'NO') as read_only
是否为只读 也即是 read_only
3 IF( MEMBER_STATE='ONLINE' AND ((SELECT COUNT(*) FROM
performance_schema.replication_group_members WHERE MEMBER_STATE != 'ONLINE') >=
((SELECT COUNT(*) FROM performance_schema.replication_group_members)/2) = 0
此为判断NODE是否正常 也即是viable_candidate
4 select COUNT_TRANSACTIONS_IN_QUEUE from replication_group_member_stats
此值为transactions_to_cert
四 总结:我们可以发现 proxysql此视图的编写时基于对performance_schema相关表的灵活组合查询运用的,我们即便不用proxysql,也可以根据此表进行有效的监控,相关创建sql可以在github上找到
五 自己写的 监控脚本
#!/bin/sh
function status()
{
result=`mysql -uroot -ptest -Ne "select $1 from sys.gr_member_routing_candidate_status"`
if [ "$result" == "YES" ];
then
status=0
map_status=1
statustxt="mgr RPE is running !"
elif [ "$result" == "NO" ];
then
status=2
map_status=1
statustxt="mgr RPE is DOWN!"
elif [ "$result" == 0 ];
then
status=0
map_status=1
statustxt=$1" value 0"
elif ["$result" > 0 ];
then
status=2
map_status=1
statustxt=$1" value "$result
else
echo "the value is vaild"
fi
echo "$status $1 $1=$status $statustxt"
}
result=`netstat -anlp|grep :3306|wc -l`
if [ "$result" == 1 ];
then
status viable_candidate
status transactions_behind
status transactions_to_cert
else
echo "mysql is down"
fi