Prometheus监控MySQL

mysql_exporter:用于收集MySQL性能信息

安装

  1. > wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
  2. > tar -xzvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
  3. > mv mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysqld_exporter
  4. > chown -R prometheus:prometheus /usr/local/mysqld_exporter

登录mysql为exporter创建账号并授权

  1. > grant process,replication client,select on *.* to 'agent'@'%' identified by '123456';
  2. > flush privileges;

配置mysqld_exporter

  1. > vim /usr/local/mysqld_exporter/.my.cnf
  2. [client]
  3. user=agent
  4. password=123456

配置成系统服务

  1. > vim /usr/lib/systemd/system/mysqld_exporter.service
  2. [Unit]
  3. Description=https://prometheus.io
  4. [Service]
  5. Restart=on-failureExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=.my.cnf
  6. [Install]
  7. WantedBy=multi-user.target

启动mysqld_exporter服务

  1. > systemctl daemon-reload
  2. > systemctl start mysqld_exporter

配置prometheus

  1. > vim /usr/local/prometheus/prometheus.yml
  2. scrape_configs:
  3. # 添加作业并命名
  4. - job_name: 'mysql'
  5. # 静态添加node
  6. static_configs:
  7. # 指定监控端
  8. - targets: ['127.0.0.1:9104']

重启prometheus服务

  1. > systemctl reload prometheus.service

查看监控端

访问:https://rumenz.com:9090/targets

图片alt

Granfana 导入Mysql 监控

选择Import,Load框输入7362

图片alt

效果展示

图片alt

返回笔记列表
入门小站