- https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
&& tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz && mv mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter && rm -rf mysqld_exporter-0.12.1.linux-amd64*">下载mysql_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
&& tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz && mv mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter && rm -rf mysqld_exporter-0.12.1.linux-amd64*
下载mysql_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
&& tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz && mv mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter && rm -rf mysqld_exporter-0.12.1.linux-amd64*
创建msql的连接权限
mysqld_exporter需要连接Mysql,首先为它创建用户并赋予所需要的权限:
GRANT REPLICATION CLIENT, PROCESS ON . TO ‘exporter’@’localhost’ identified by ‘123456’;
GRANT SELECT ON performance_schema.* TO ‘exporter’@’localhost’;
flush privileges;
创建.my.cnf文件
在当前的用户目录(可变更)创建.my.cnf文件
cat > .my.cnf<
user=exporter
password=123456
设置mysql_exporter开启启动
cat >/usr/lib/systemd/system/mysql_exporter.service<<EOF[Unit]Description=mysqld_exporterDocumentation=https://prometheus.io/docsAfter=network.target[Service]User=rootGroup=rootType=simpleExecStart=/usr/bin/mysqld_exporter \--collect.info_schema.processlist \--collect.info_schema.innodb_tablespaces \--collect.info_schema.innodb_metrics \--collect.perf_schema.tableiowaits \--collect.perf_schema.indexiowaits \--collect.perf_schema.tablelocks \--collect.engine_innodb_status \--collect.perf_schema.file_events \--collect.binlog_size \--collect.info_schema.clientstats \--collect.perf_schema.eventswaits \--config.my-cnf=/root/.my.cnfRestart=on-failure[Install]WantedBy=multi-user.targetEOF# 启动 mysql_exportersystemctl start mysql_exporter.service && systemctl status mysql_exporter.service# 默认端口9104
使用granafa给 MySQLD_Exporter添加监控图表
- 主从主群监控(模板7371):https://grafana.com/grafana/dashboards/7371
- 相关mysql 状态监控7362:https://grafana.com/grafana/dashboards/7362
- 缓冲池状态7365: https://grafana.com/grafana/dashboards/7365
参考
https://www.xxlaila.cn/2020/04/12/Prometheus%E7%9B%91%E6%8E%A7%E5%BA%94%E7%94%A8/
