-
Notifications
You must be signed in to change notification settings - Fork 31
Monitor Module
本文内容主要介绍1.2.1版本之后的Monitor模块,因为相比1.2.0版本,1.2.1版修改了不少地方。
不再使用或已废弃的变量:
- mysql-monitor_query_variables
- mysql-monitor_query_status
- mysql-monitor_timer_cached
已不再使用的变量:
- mysql-monitor_query_interval
- mysql-monitor_query_timeout
Monitor模块用于定期检查后端的各项指标。当前支持4种类型的指标检查:
-
connect:连接到各后端是否成功,成功/失败的连接将记录到表
mysql_server_connect_log
中。 -
ping:向所有后端发起ping检查,ping成功/失败的情况将记录到表
mysql_server_ping_log
中。当ping某后端的失败次数达到了mysql-monitor_ping_max_failures
时表示失去心跳,将发送一个信号给MySQL的主机组管理器来杀掉和该后端节点的所有连接。 -
replication lag:对所有配置了
max_replication_lag
的后端slave节点都检查复制延迟,通过Seconds_Behind_Master
进行判断slave和master之间的延迟程度,并记录到mysql_server_replication_lag_log
表中。如果Seconds_Behind_Master
>max_replication_lag
,表示该slave延迟很严重,ProxySQL会自动避开这种slave节点,直到Seconds_Behind_Master
<max_replication_lag
。 -
read only:检查
mysql_replication_hostgroups
表中所有hostgroup内的节点的read_only
值,并记录到mysql_server_read_only_log
。如果read_only=1
,表示只读,是一个slave,这样的节点将会自动移入reader_hostgroup
中,如果read_only=0
,表示可写,可能是master,这样的节点将会自动移入writer_hostgroup
中。
通用变量:
-
mysql-monitor_username
指定Monitor连接后端时使用的用户名。该用户只需具有
USAGE
权限即可完成connect
、ping
和read_only
这三类检查。如果还需检查replication lag,则该用户需要具有REPLICATION CLIENT
权限。 -
mysql-monitor_password
mysql-monitor_username对应的密码。
-
mysql-monitor_enabled
该变量用于启用/禁用 Monitor 模块。因为可以通过Admin管理接口直接改变Monitor的行为,所以这个变量可用来临时禁用Monitor。
connect检查相关的变量:
-
mysql-monitor_connect_interval
connect
检查的时间间隔,毫秒。 -
mysql-monitor_connect_timeout
Monitor模块和后端建立连接时的超时时间,毫秒。目前,这个时间会向下舍入为小于或等于此处给定值转换为秒的整数(译注:给定2200毫秒,会转换为2秒)。允许的最小值为1秒。这种懒惰的"四舍五入"行为是因为SSL连接是阻塞模型的调用。
Ping检查相关变量:
-
mysql-monitor_ping_interval
ping
检查的时间间隔,毫秒。 -
mysql-monitor_ping_timeout
ping检查(等待回复)的超时时间,毫秒。
-
mysql-monitor_ping_max_failures
如果ping某后端节点时,连续失败的次数达到了
mysql-monitor_ping_max_failures
,则Monitor认为该节点不可达到,于是会通知组管理器杀掉和该节点已建立的所有连接。
需要注意,connect和Ping检查都能确定某后端是否可达,所以以下两种时间都可用来确定节点是否真的故障:- mysql-monitor_ping_max_failures * mysql-monitor_connect_timeout
- mysql-monitor_ping_max_failures * mysql-monitor_ping_timeout
Read_only检查相关变量:
-
mysql-monitor_read_only_interval
read_only
检查的时间间隔,毫秒。 -
mysql-monitor_read_only_timeout
read_only
检查超时时间,毫秒。 -
mysql-monitor_writer_is_also_reader
当某节点的
read_only
值从1改为0时,该变量决定该节点是否同时存在于读、写组:-
false:该节点将从读组
reader_hostgroup
移入writer_hostgroup
,该节点将从reader_hostgroup
中删除。 -
true:该节点将从读组
reader_hostgroup
拷贝到writer_hostgroup
,该节点不会从reader_hostgroup
中删除。
-
false:该节点将从读组
Replication lag检查相关的变量:
-
mysql-monitor_replication_lag_interval
replication lag检查的时间间隔,毫秒。
-
mysql-monitor_replication_lag_timeout
Replication lag检查的超时时间,毫秒。
其它变量:
-
mysql-monitor_history
为了防止Monitor log类的表无限增长,Monitor模块会自动purge掉变量
mysql-monitor_history
(毫秒)指定时间之前的日志记录。但由于ping检查依赖于ping log表来决定某节点是否正处于丢失心跳状态,所以当mysql-monitor_history
的值小于下面的值时,会自动调整该变量的值为以下值:- (mysql-monitor_ping_max_failures + 1 ) * mysql-monitor_ping_timeout
(译注:即保证ping检查在完成之前,不对ping的日志表进行purge)
Monitor模块有好几种内部线程。当前有5种main线程:
- Monitor:master线程,负责启动和协调其它线程。
- monitor_connect_thread:一个main线程,负责定期执行
connect
检查。 - monitor_ping_thread:一个main线程,负责定期执行
ping
检查。 - monitor_read_only_thread:一个main线程,负责定期执行
read_only
检查。 - monitor_replication_lag_thread:一个main线程,负责定期执行
replication lag
检查。
(Monitor的线程池)
ProxySQL 1.2.0中对于使用SSL有一个限制:使用SSL时,connect()
是一个阻塞类型的调用,会导致线程在建立连接的阶段停止。
在ProxySQL 1.2.1,通过一种新的方式克服了该局限性:
- Monitor线程会初始化一个线程池,同时创建一个队列。
- monitor_connect_thread, monitor_ping_thread, monitor_read_only_thread 以及 monitor_replication_lag_thread,这几个线程是任务的生产者,并将生成的任务放进队列中等待消费者worker线程取走。
- workers线程处理这些这些任务。
- 如果 Monitor 线程探测到队列增长速度过快,将会临时创建新的worker线程。
(译注:所以,除了上面5种线程,Monitor模块还有worker线程)
Monitor有它自己的连接池。当连接池中空闲连接的空闲时长达到了 3 * mysql-monitor_ping_interval
(毫秒)后,该空闲连接将自动被purge。
(译注:这个变量的默认值为60000毫秒,即1分钟,所以monitor模块连接池中的每个空闲连接最长空闲3分钟,)
为了避免后端中断连接,Monitor模块自动配置wait_timeout
= mysql-monitor_ping_interval
* 10,使得连接等待一段时间后连接自动断开。
Translator:马龙帅
Blog:http://www.cnblogs.com/f-ck-need-u
- 须知:本译文适用于ProxySQL 1.4.4及之后版本
- 快速开始
- 配置使用ProxySQL
- 一步一步配置ProxySQL(HOWTO)
- ProxySQL读/写分离方法论(HOWTO)
- ProxySQL的线程
- Multiplexing
- 查询缓存
- Monitor模块
- ProxySQL集群
- 设计目标
- FAQ
- 以下是无关紧要或正处于测试中的内容,不翻译
- SSL configuration(不翻译)
- HTTP Web Server(不翻译)
- Clickhouse Support(不翻译)
- Mirroring(不翻译)
- 探测内存泄漏(不翻译)
- 错误代码(不翻译)
- 程序包制作(不翻译)