Prometheus 监控Mysql服务器及Grafana可视化

Prometheus 监控Mysql服务器及Grafana可视化、

mysql_exporter:用于收集MySQL性能信息。

  • 使用版本
  • mysqld_exporter 0.11.0
  • 官方地址
  • 使用文档:https://github.com/prometheus/mysqld_exporter
  • 图标模板:https://grafana.com/dashboards/7362
  • 下载地址:https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
  • 百度云:mysqld_exporter 0.11.0
  • 下载地址:https://pan.baidu.com/s/1JfjbK3uOMXObc7-F8h13Dw
  • 密码:dxsn

注:要求数据库mysql 5.5 以上版本。

 

安装mysql_exporter

1、下载到被监控端解压压缩包

tar zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz 

2、改名并移动到指定目录

mv mysqld_exporter-0.11.0.linux-amd64 /usr/local/mysql_exporter
cd /usr/local/mysql_exporter

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

# 创建数据库用户。
mysql> CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX';
# 可查看主从运行情况查看线程,及所有数据库。
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';

4、创建mysql配置文件、运行时可免密码连接数据库:vim /usr/local/mysql_exporter/.my.cnf

[client]
user=exporter
password=xiangsikai

5、启动exporter客户端

./mysqld_exporter --config.my-cnf=.my.cnf
常用参数:
# 选择采集innodb
--collect.info_schema.innodb_cmp
# innodb存储引擎状态
--collect.engine_innodb_status
# 指定配置文件
--config.my-cnf=".my.cnf"
启动常用参数

6、添加系统服务:vi /usr/lib/systemd/system/mysql_exporter.service

[Unit]
Description=https://prometheus.io

[Service]
Restart=on-failureExecStart=/usr/local/mysql_exporter/mysqld_exporter --config.my-cnf=.my.cnf 

[Install]
WantedBy=multi-user.target

7、启动添加后的系统服务

systemctl daemon-reload
systemctl restart mysql_exporter.service

8、网站查看捕获mysql数据

访问:http://47.98.138.176:9104/metrics

9、使用prometheus监控修改监控端配置文件:vim prometheus.yml

scrape_configs:
  # 添加作业并命名
  - job_name: 'mysql'
    # 静态添加node
    static_configs:
    # 指定监控端
    - targets: ['47.98.138.176:9104']

10、检查并重启服务

./promtool check config prometheus.yml 
kill -hup 5997

11、查看监控端是否介入

12、使用promSQL查看mysql监控信息

# 测试查看mysqlglobal状态信息
mysql_global_status_aborted_clients
PromSQL

13、Granfana 导入Mysql 监控图表

  • 推荐图标ID:https://grafana.com/dashboards/7362

14、输入导入图标ID等待3秒弹出如下,修改后保存

15、监控展示

 

posted @ 2019-08-02 16:53  kevin.Xiang  阅读(24150)  评论(1编辑  收藏  举报