构建高峻上的MySQL监控平台(2)

在利用show slave status 内里尚有一个要害的参数Seconds_Behind_Master。Seconds_Behind_Master暗示slave上SQL thread与IO thread之间的延迟,我们都知道在MySQL的复制情况中,slave先从master大将binlog拉取到当地(通过IO thread),然后通过SQL thread将binlog重放,而Seconds_Behind_Master暗示当地relaylog中未被执行完的那部门的差值。所以假如slave拉取到当地的relaylog(实际上就是binlog,只是在slave上习惯称号relaylog罢了)都执行完,此时通过show slave status看到的会是0

Seconds_Behind_Master: 0

MySQLD Exporter中返回的样本数据中通过mysql_slave_status_seconds_behind_master 来获取相关状态。

# HELP mysql_slave_status_seconds_behind_master Generic metric from SHOW SLAVE STATUS. # TYPE mysql_slave_status_seconds_behind_master untyped mysql_slave_status_seconds_behind_master{channel_name="",connection_name="",master_host="172.16.1.1",master_uuid=""} 0 查询吞吐量:

说到吞吐量,那么我们如何从那方面来权衡呢?
凡是来说我们可以按照mysql 的插入、查询、删除、更新等操纵来

为了获取吞吐量,MySQL 有一个名为 Questions 的内部计数器(按照 MySQL 用语,这是一个处事器状态变量),客户端每发送一个查询语句,其值就会加一。由 Questions 指标带来的以客户端为中心的视角经常比相关的Queries 计数器更容易表明。作为存储措施的一部门,后者也管帐算已执行语句的数量,以及诸如PREPARE 和 DEALLOCATE PREPARE 指令运行的次数,作为处事器端预处理惩罚语句的一部门。可以通过呼吁来查询:

MariaDB [(none)]> SHOW GLOBAL STATUS LIKE "Questions"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Questions | 15071 | +---------------+-------+

MySQLD Exporter中返回的样本数据中通过mysql_global_status_questions反该当前Questions计数器的巨细:

# HELP mysql_global_status_questions Generic metric from SHOW GLOBAL STATUS. # TYPE mysql_global_status_questions untyped mysql_global_status_questions 13253

虽然由于prometheus 具有很是富厚的查询语言,我们可以通过这个累加的计数器来查询某一短时间内的查询增长率环境,可以做相关的阈值告警处理惩罚、譬喻一下查询2分钟时间内的查询环境:

rate(mysql_global_status_questions[2m])

虽然上面是总量,我们可以别离从监控读、写指令的解析环境,从而更好地领略数据库的事情负载、找到大概的瓶颈。凡是,凡是,读取查询会由 Com_select 指标抓取,而写入查询则大概增加三个状态变量中某一个的值,这取决于详细的指令:

Writes = Com_insert + Com_update + Com_delete

下面我们通过呼吁获取插入的环境:

MariaDB [(none)]> SHOW GLOBAL STATUS LIKE "Com_insert"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Com_insert | 10578 | +---------------+-------+

从MySQLD Exporter的/metrics返回的监控样本中,可以通过global_status_commands_total获取当前实例种种指令执行的次数:

# HELP mysql_global_status_commands_total Total number of executed MySQL commands. # TYPE mysql_global_status_commands_total counter mysql_global_status_commands_total{command="create_trigger"} 0 mysql_global_status_commands_total{command="create_udf"} 0 mysql_global_status_commands_total{command="create_user"} 1 mysql_global_status_commands_total{command="create_view"} 0 mysql_global_status_commands_total{command="dealloc_sql"} 0 mysql_global_status_commands_total{command="delete"} 3369 mysql_global_status_commands_total{command="delete_multi"} 0 慢查询机能

查询机能方面,慢查询也是查询告警的一个重要的指标。MySQL还提供了一个Slow_queries的计数器,当查询的执行时间高出long_query_time的值后,计数器就会+1,其默认值为10秒,可以通过以下指令在MySQL中查询当前long_query_time的配置:

MariaDB [(none)]> SHOW VARIABLES LIKE 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+ 1 row in set (0.00 sec)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsdjdp.html