构建高峻上的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/wsdjdp.html