thread将binlog重放,而Seconds_Behind_Master表示本地relaylog中未被执行完的那部分的差值 。所以如果slave拉取到本地的relaylog(实际上就是binlog,只是在slave上习惯称呼relaylog而已)都执行完,此时通过show slave status看到的会是0
Seconds_Behind_Master: 0MySQLD 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 untypedmysql_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 untypedmysql_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 |+---------------+-------+
从MySQLDExporter的/metrics返回的监控样本中,可以通过
global_status_commands_total获取当前实例各类指令执行的次数:
# HELP mysql_global_status_commands_total Total number of executed MySQL commands.# TYPE mysql_global_status_commands_total countermysql_global_status_commands_total{command="create_trigger"} 0mysql_global_status_commands_total{command="create_udf"} 0mysql_global_status_commands_total{command="create_user"} 1mysql_global_status_commands_total{command="create_view"} 0mysql_global_status_commands_total{command="dealloc_sql"} 0mysql_global_status_commands_total{command="delete"} 3369mysql_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)
当然我们也可以修改时间MariaDB [(none)]> SET GLOBAL long_query_time = 5;Query OK, 0 rows affected (0.00 sec)
然后我们而已通过sql语言查询MySQL实例中Slow_queries的数量:MariaDB [(none)]> SHOW GLOBAL STATUS LIKE "Slow_queries";+---------------+-------+| Variable_name | Value |+---------------+-------+| Slow_queries| 0|+---------------+-------+1 row in set (0.00 sec)
MySQLDExporter返回的样本数据中,通过
mysql_global_status_slow_queries指标展示当前的Slow_queries的值:
# HELP mysql_global_status_slow_queries Generic metric from SHOW GLOBAL STATUS.# TYPE mysql_global_status_slow_queries untypedmysql_global_status_slow_queries 0
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 基于netty构建一个http服务
- 基于netty的构建一个群聊系统
- 新房家里的局域网如何布线
- 在Pytorch中构建流数据集
- 我是如何在 Go 中构建 Web 服务的
- 手把手教你用 FastDFS 构建分布式文件管理系统
- 超详细Prometheus入门教程
- 数据仓库构建流程
- 基于阿里Ant Design构建的高颜值开源管理后台UI框架
- 不用Docker也能构建容器的4种方法