prometheus监控之Mysql监控

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了prometheus监控之Mysql监控相关的知识,希望对你有一定的参考价值。

下载mysql_exporter

众所周知prometheus监控使用各种exporter,官方的exporter就能支持主流的大多数应用的中间件,同样,监控Mysql需要安装mysql_exporter,下载地址:https://github.com/prometheus/mysqld_exporter/releases

编辑配置文件

vi my.cnf
client]
host=10.10.10.230
port=23306
user=mysqlexporter
password=mysqlexporter

这里面就是需要监控的mysql主机地址端口,用于连接的账号密码

创建账号密码

在mysql主机上创建账号密码

mysql> create user if not exists mysqlexporter identified by mysqlexporter;
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO mysqlexporter@10.10.10.103;
mysql> flush privileges;

启动mysql_exporter

nohup /usr/bin/mysqld_exporter --config.my-cnf=/deploy/mysql_8.0/mysql_exporter/my.cnf &

prometheus添加job_name:mysql_exporter

  - job_name: "mysqld_exporter"
    static_configs:
      - targets: [10.10.10.230:9104]

alertmanager添加报警规则

- name: Mysql Expoter
  rules:
  - alert: MysqlDown
    expr: mysql_up == 0
    for: 0m
    labels:
      severity: critical
    annotations:
      summary: MySQL down (instance  $labels.instance )
      description: "MySQL instance is down on  $labels.instance \\n  VALUE =  $value \\n  LABELS =  $labels "
  - alert: MysqlTooManyConnections(>80%)
    expr: max_over_time(mysql_global_status_threads_connected[1m]) / mysql_global_variables_max_connections * 100 > 80
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MySQL too many connections (> 80%) (instance  $labels.instance )
      description: "More than 80% of MySQL connections are in use on  $labels.instance \\n  VALUE =  $value \\n  LABELS =  $labels "
  - alert: MysqlHighThreadsRunning
    expr: max_over_time(mysql_global_status_threads_running[1m]) / mysql_global_variables_max_connections * 100 > 60
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MySQL high threads running (instance  $labels.instance )
      description: "More than 60% of MySQL connections are in running state on  $labels.instance \\n  VALUE =  $value \\n  LABELS =  $labels "
  - alert: MysqlSlowQueries
    expr: increase(mysql_global_status_slow_queries[1m]) > 0
    for: 2m
    labels:
      severity: warning
    annotations:
      summary: MySQL slow queries (instance  $labels.instance )
      description: "MySQL server mysql has some new slow query.\\n  VALUE =  $value \\n  LABELS =  $labels "
  - alert: MysqlInnodbLogWaits
    expr: rate(mysql_global_status_innodb_log_waits[15m]) > 10
    for: 0m
    labels:
      severity: warning
    annotations:
      summary: MySQL InnoDB log waits (instance  $labels.instance )
      description: "MySQL innodb log writes stalling\\n  VALUE =  $value \\n  LABELS =  $labels "
  - alert: MysqlRestarted
    expr: mysql_global_status_uptime < 60
    for: 0m
    labels:
      severity: info
    annotations:
      summary: MySQL restarted (instance  $labels.instance )
      description: "MySQL has just been restarted, less than one minute ago on  $labels.instance .\\n  VALUE =  $value \\n  LABELS =  $labels "

查看是否生效

target已添加 rules已添加 alerts已添加

以上是关于prometheus监控之Mysql监控的主要内容,如果未能解决你的问题,请参考以下文章

监控利器之Prometheus服务监控-上篇

大数据组件监控之-Prometheus监控mysql5.x数据库

超级实用,解密云原生监控技术,使用prometheus轻松搞定redis监控

Prometheus监控之mysqld_exporter

云原生系列之使用prometheus监控redis集群实战

Prometheus+Grafana监控MySQL浅析