构建高大上的MySQL监控平台(4)

MySQLD Exporter返回的样本数据中,使用mysql_global_variables_innodb_buffer_pool_size来表示。

# HELP mysql_global_variables_innodb_buffer_pool_size Generic gauge metric from SHOW GLOBAL VARIABLES. # TYPE mysql_global_variables_innodb_buffer_pool_size gauge mysql_global_variables_innodb_buffer_pool_size 1.34217728e+08 Innodb_buffer_pool_read_requests记录了正常从缓冲池读取数据的请求数量。可以通过以下指令查看 MariaDB [(none)]> SHOW GLOBAL STATUS LIKE "Innodb_buffer_pool_read_requests"; +----------------------------------+-------------+ | Variable_name | Value | +----------------------------------+-------------+ | Innodb_buffer_pool_read_requests | 38465 | +----------------------------------+-------------+

MySQLD Exporter返回的样本数据中,使用mysql_global_status_innodb_buffer_pool_read_requests来表示。

# HELP mysql_global_status_innodb_buffer_pool_read_requests Generic metric from SHOW GLOBAL STATUS. # TYPE mysql_global_status_innodb_buffer_pool_read_requests untyped mysql_global_status_innodb_buffer_pool_read_requests 2.7711547168e+10

当缓冲池无法满足时,MySQL只能从磁盘中读取数据。Innodb_buffer_pool_reads即记录了从磁盘读取数据的请求数量。通常来说从内存中读取数据的速度要比从磁盘中读取快很多,因此,如果Innodb_buffer_pool_reads的值开始增加,可能意味着数据库的性能有问题。 可以通过以下只能查看Innodb_buffer_pool_reads的数量

MariaDB [(none)]> SHOW GLOBAL STATUS LIKE "Innodb_buffer_pool_reads"; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | Innodb_buffer_pool_reads | 138 | +--------------------------+-------+ 1 row in set (0.00 sec)

MySQLD Exporter返回的样本数据中,使用mysql_global_status_innodb_buffer_pool_read_requests来表示。

# HELP mysql_global_status_innodb_buffer_pool_reads Generic metric from SHOW GLOBAL STATUS. # TYPE mysql_global_status_innodb_buffer_pool_reads untyped mysql_global_status_innodb_buffer_pool_reads 138

通过以上监控指标,以及实际监控的场景,我们可以利用PromQL快速建立多个监控项。可以查看两分钟内读取磁盘的增长率的增长率:

rate(mysql_global_status_innodb_buffer_pool_reads[2m])

官方模板ID

上面是我们简单列举的一些指标,下面我们使用granafa给 MySQLD_Exporter添加监控图表:

主从主群监控(模板7371):

相关mysql 状态监控7362:

缓冲池状态7365:

简单的告警规则

除了相关模板之外,没有告警规则那么我们的监控就是不完美的,下面列一下我们的监控告警规则

groups: - name: MySQL-rules rules: - alert: MySQL Status expr: up == 0 for: 5s labels: severity: warning annotations: summary: "{{$labels.instance}}: MySQL has stop !!!" description: "检测MySQL数据库运行状态" - alert: MySQL Slave IO Thread Status expr: mysql_slave_status_slave_io_running == 0 for: 5s labels: severity: warning annotations: summary: "{{$labels.instance}}: MySQL Slave IO Thread has stop !!!" description: "检测MySQL主从IO线程运行状态" - alert: MySQL Slave SQL Thread Status expr: mysql_slave_status_slave_sql_running == 0 for: 5s labels: severity: warning annotations: summary: "{{$labels.instance}}: MySQL Slave SQL Thread has stop !!!" description: "检测MySQL主从SQL线程运行状态" - alert: MySQL Slave Delay Status expr: mysql_slave_status_sql_delay == 30 for: 5s labels: severity: warning annotations: summary: "{{$labels.instance}}: MySQL Slave Delay has more than 30s !!!" description: "检测MySQL主从延时状态" - alert: Mysql_Too_Many_Connections expr: rate(mysql_global_status_threads_connected[5m]) > 200 for: 2m labels: severity: warning annotations: summary: "{{$labels.instance}}: 连接数过多" description: "{{$labels.instance}}: 连接数过多,请处理 ,(current value is: {{ $value }})" - alert: Mysql_Too_Many_slow_queries expr: rate(mysql_global_status_slow_queries[5m]) > 3 for: 2m labels: severity: warning annotations: summary: "{{$labels.instance}}: 慢查询有点多,请检查处理" description: "{{$labels.instance}}: Mysql slow_queries is more than 3 per second ,(current value is: {{ $value }})"

2、添加规则到prometheus:

rule_files: - "rules/*.yml"

3、打开web ui我们可以看到规则生效了:

构建高大上的MySQL监控平台

总结

到处监控mysql的相关状态已经完成,大家可以根据mysql更多的监控指标去完善自己的监控,当然这一套就是我用在线上环境的,可以参考参考。

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

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