架构

在需要监控的mysql上安装 node_exporter和 mysqld_exporter

架构示意图:​​https://processon.com/diagraming/6028831e079129342249700e​

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_linux


下载

​https://github.com/prometheus/mysqld_exporter/releases​

​https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz​


安装、配置、验证

解压

tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_mysql_02

修改配置文件

vim .my.cnf

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_mysql_03

添加获取mysql监控数据的账号,如果不写端口,默认为3306

(根据自己安装的mysql实际情况填写)

[client]
user=root
password=mysql123
port=3206



也可以另外创建用户并授权

GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'mysql_exporter'@'localhost' identified by '123456';
GRANT SELECT ON performance_schema.* TO 'mysql_exporter'@'localhost';
flush privileges;



启动服务

./mysqld_exporter --config.my-cnf=".my.cnf"

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_mysql_04

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_mysql_05


验证:http://IP:9104/metrics

搜索:max_connections

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_javascript_06


在prometheus.yml中加入job

- job_name: 'mysql'
static_configs:
- targets: ['localhost:9104']



重启prometheus:nohup /usr/local/prometheus-2.19.1.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.19.1.linux-amd64/prometheus.yml &

​http://ip:9090/targets​

mysql的状态变成up了

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_javascript_07


Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_javascript_08


grafana导入模板 

​https://grafana.com/grafana/dashboards/7362​

导入

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_javascript_09


Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_linux_10


效果(报告含义不清楚的可以咨询作者)

Prometheus环境搭建系列(二):监控mysql服务器(mysqld_exporter)_linux_11





============================= 提升自己 ==========================

如有侵权,请联系删除。

============================= 升职加薪 ==========================